blob: 4df92efad2e44bcc6af35a14908b337ea83cb71a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2* @file netotherapi.h
3* @brief Public APIs of Sanechips , linux network external interface
4*
5* Copyright (C) 2017 Sanechips Technology Co., Ltd.
6* @author Linxu Gebin
7* @defgroup si_id Sanechips
8*
9* This program is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License version 2 as
11* published by the Free Software Foundation.
12*************************************************************************
13*/
14
15#ifndef __NETOTHERAPI_H__
16#define __NETOTHERAPI_H__
17#include "zxic_list.h"
18
19#ifndef DOXYGEN_SHOULD_SKIP_THIS
20
21/*******************************************************************************
22 * Macro definitions *
23******************************************************************************/
24
25#define WAKE_LOCK_PATH "/sys/power/wake_lock"
26#define WAKE_UNLOCK_PATH "/sys/power/wake_unlock"
27
28
29
30#define PROC_IF_STATISTIC "/proc/net/dev"
31#define TXBYTE 0 //·¢ËÍÊý¾Ý
32#define TXPACKET 1
33#define RXBYTE 2 //½ÓÊÕÊý¾Ý
34#define RXPACKET 3
35
36#define PC_MAX_NUM 100
37#define DEV_NAME_LEN 50
38#define TIMER_GETHOSTBYNAME_ID 62
39
40#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
41
42/* Used to retry syscalls that can return EINTR. */
43#ifndef TEMP_FAILURE_RETRY
44#define TEMP_FAILURE_RETRY(exp) ({ \
45 typeof (exp) _rc; \
46 do{ \
47 _rc = (exp); \
48 }while((_rc == -1) && (errno == EINTR)); \
49 _rc; })
50#endif
51
52/*******************************************************************************
53 * Type definitions *
54 ******************************************************************************/
55
56struct pc_info {
57 unsigned char mac_addr[6];
58 char dev_name[DEV_NAME_LEN];
59};
60struct pc_node {
61 unsigned int num;
62 struct pc_info info[PC_MAX_NUM];
63};
64
65
66/**
67* @brief ÄÚÍøÐÅÏ¢
68* @param mac mac µØÖ·
69* @param ip ip µØÖ·
70* @param hostname Ö÷»úÃû
71* @param dev_name É豸Ãû
72* @param time_remain µ±Ç°Ê±¼äµ½ÉÏÒ»¸üиÃÉ豸ÐÅÏ¢¼ä¸ôʱ¼ä
73* @param time_last ×î½üÒ»´Î¸üÐÂʱ¼äµã
74* @note ÎÞ
75*/
76typedef struct LAN_INFO {
77 unsigned char mac[6];
78 unsigned long ip;
79 char host_name[32];
80 char dev_name[32];
81 unsigned long time_remain;
82 unsigned long time_last;
83} LAN_INFO_t;
84
85/**
86* @brief ÄÚÍøÐÅÏ¢Á´±í
87* @param list_head Á´±íÍ·½Úµã
88* @param lan_info lÄÚÍøÐÄÏ¢
89* @note ÎÞ
90*/
91typedef struct LAN_INFO_LIST {
92 struct list_head list;
93 LAN_INFO_t lan_info;
94} LAN_INFO_LIST_t;
95
96/**
97* @brief dhcp server´æ´¢µÄleaseÎļþ½á¹¹Ìå
98* @param expires expires
99* @param ip ip µØÖ·
100* @param mac mac µØÖ·
101* @param host_nameÖ÷»úÃû
102* @param pad
103*/
104typedef struct _DHCPOFFERADDRNET {
105 unsigned long expires;
106 unsigned long ip;
107 unsigned char mac[6];
108 unsigned char host_name[20];
109 unsigned char pad[2];
110} DHCPOFFERADDRNET;
111
112/**
113* @brief dhcp ÐÅÏ¢Á´±í
114* @param list Á´±íÍ·½Úµã
115* @param dhcp_info dhcp ÐÅÏ¢
116*/
117typedef struct _DHCPOFFERADDR_LIST {
118 struct list_head list;
119 DHCPOFFERADDRNET dhcp_info;
120} DHCPOFFERADDR_LIST_t;
121/**
122* @brief dhcp gethostbynameÐÅÏ¢
123* @param time ³¬Ê±Ê±¼ä£¬µ¥Î»ÎªºÁÃë
124* @param ¶ÓÁкÅ
125*/
126struct gethostbyname_info{
127 int time;
128 char name[HOSTNAME_LEN];
129 int msg_id;
130};
131
132
133/*******************************************************************************
134 * Global function declarations *
135 ******************************************************************************/
136
137/**
138* @brief ´Ódhcpd.leasesÎļþÖлñÈ¡dhcpÐÅÏ¢
139* @param dhcp_list_info dhcp ÐÅÏ¢Á´±í
140* @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1
141*/
142int zte_get_mac_list_from_lease(struct list_head *dhcp_list_info);
143
144/**
145* @brief É豸ÐÅÏ¢
146* @param mypc_node É豸ÐÅÏ¢Á´±í
147* @param info information
148* @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1
149*/
150int get_dev_list(struct pc_node* mypc_node);
151
152/**
153* @brief ±£´æÐÅÏ¢µ½Îļþ
154* @param filename ÎļþÃû
155* @param info ÐèÒª±£´æµÄÐÅÏ¢
156* @return ÎÞ
157*/
158void save_file(char *filename, char* info);
159
160/**
161* @brief дÐÅÏ¢µ½Îļþ
162* @param filename ÎļþÃû
163* @param info ÐèҪдµÄÐÅÏ¢
164* @return ÎÞ
165*/
166void file_write(char *filename, char *info);
167
168/**
169* @brief ÊÍ·ÅdhcpÐÅÏ¢Á´±í
170* @param dhcp_info_list dhcpÁ´±íÍ·½áµã
171* @return ÎÞ
172*/
173void free_dhcp_list(struct list_head * dhcp_info_list);
174
175/**
176* @brief ÊÍ·ÅÄÚÍøÐÅÏ¢Á´±í
177* @param dhcp_info_list ÄÚÍøÐÅÏ¢Á´±íÍ·½áµã
178* @return ÎÞ
179*/
180void free_laninfo_list(struct list_head * dhcp_info_list);
181
182/**
183* @brief »ñÈ¡É豸ÐÅÏ¢
184* @param interface ÍøÂçÉ豸Ãû
185* @param type Êý¾ÝÀàÐÍ
186* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·Å»Ø-1
187*/
188int getIfStatistic(char *interface, int type, unsigned long long *result_data);
189
190/**
191 * @brief »ñÈ¡wakelockËø
192 * @param lockId wakelockËøID
193 * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
194 */
195int set_wake_lock(const char *lockId);
196
197/**
198 * @brief »ñÈ¡wakelock³¬Ê±Ëø
199 * @param lockId wakelockËøID
200 * @param interval ³¬Ê±Ê±¼ä£¬µ¥Î»: Ãë
201 * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
202 */
203int set_wake_lock_timeout(const char *lockId, unsigned long interval);
204
205/**
206 * @brief ÊÍ·ÅwakelockËø
207 * @param lockId wakelockËøID
208 * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
209 */
210int set_wake_unlock(const char *lockId);
211
212
213int get_lan_info_list(struct list_head *file_list_info);
214
215/**
216 * @brief ÉêÇëÄÚ´æ
217 * @param size ÉêÇëÄÚ´æ´óС
218 * @param is_assert£¬ÉêÇëʧ°ÜÊÇ·ñassert
219 * @return ÉêÇë³É¹¦·µ»ØÉêÇëÄÚ´æµØÖ·£»Ê§°Ü·µ»ØNULL
220 */
221void *safe_malloc(int size, BOOL is_assert);
222
223unsigned long time_sec();
224
225
226/**
227* @brief »ñȡָ¶¨Ïß³ÌÃûµÄpidºÅ
228* @param pidNameΪ½ø³ÌÃû
229* @return ³É¹¦·µ»Ø½ø³ÌºÅpid_tÀàÐÍÖ¸Õë
230* @note µ÷Óøú¯Êý»ñÈ¡·µ»ØÖµ£¬Ê¹ÓúóÒ»¶¨ÒªÊͷŸÃÄÚ´æ¿Õ¼ä
231*/
232pid_t* find_pid_by_name(char *pidName);
233
234/**
235* @brief ¾ßÓг¬Ê±´¦ÀíµÄgethostbyname
236* @param name url
237* @param time ³¬Ê±Ê±³¤,µ¥Î»:Ãë, 0¾ÍÊDZê×¼µÄgethostbyname¹¦ÄÜ
238* @return hostÐÅÏ¢
239* @Note: ͬһ½ø³ÌͬʱֻÄܵ÷ÓÃÒ»´Î¸Ã½Ó¿Ú
240*/
241struct hostent *gethostbyname_t(const char *name, int time);
242
243/**
244* @±¾µØ¼¤»î»ñÈ¡dns½Ó¿Ú£¬²»ÒÀÀµÂ·ÓÉ£¬·µ»ØÖµÎªu32ÀàÐÍipµØÖ·
245*/
246unsigned long gethostbyname_l(char *hostname,char* dev_name);
247
248#endif
249
250#endif /* __NETOTHERAPI_H__ */