lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /** |
| 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 |
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 35 | #define TXERR 4 |
| 36 | #define TXDROP 5 |
| 37 | #define RXERR 6 |
| 38 | #define RXDROP 7 |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 39 | |
| 40 | #define PC_MAX_NUM 100 |
| 41 | #define DEV_NAME_LEN 50 |
| 42 | #define TIMER_GETHOSTBYNAME_ID 62 |
| 43 | |
| 44 | #define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0) |
| 45 | |
| 46 | /* Used to retry syscalls that can return EINTR. */ |
| 47 | #ifndef TEMP_FAILURE_RETRY |
| 48 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
| 49 | typeof (exp) _rc; \ |
| 50 | do{ \ |
| 51 | _rc = (exp); \ |
| 52 | }while((_rc == -1) && (errno == EINTR)); \ |
| 53 | _rc; }) |
| 54 | #endif |
| 55 | |
| 56 | /******************************************************************************* |
| 57 | * Type definitions * |
| 58 | ******************************************************************************/ |
| 59 | |
| 60 | struct pc_info { |
| 61 | unsigned char mac_addr[6]; |
| 62 | char dev_name[DEV_NAME_LEN]; |
| 63 | }; |
| 64 | struct pc_node { |
| 65 | unsigned int num; |
| 66 | struct pc_info info[PC_MAX_NUM]; |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * @brief ÄÚÍøÐÅÏ¢ |
| 72 | * @param mac mac µØÖ· |
| 73 | * @param ip ip µØÖ· |
| 74 | * @param hostname Ö÷»úÃû |
| 75 | * @param dev_name É豸Ãû |
| 76 | * @param time_remain µ±Ç°Ê±¼äµ½ÉÏÒ»¸üиÃÉ豸ÐÅÏ¢¼ä¸ôʱ¼ä |
| 77 | * @param time_last ×î½üÒ»´Î¸üÐÂʱ¼äµã |
| 78 | * @note ÎÞ |
| 79 | */ |
| 80 | typedef struct LAN_INFO { |
| 81 | unsigned char mac[6]; |
| 82 | unsigned long ip; |
| 83 | char host_name[32]; |
| 84 | char dev_name[32]; |
| 85 | unsigned long time_remain; |
| 86 | unsigned long time_last; |
| 87 | } LAN_INFO_t; |
| 88 | |
| 89 | /** |
| 90 | * @brief ÄÚÍøÐÅÏ¢Á´±í |
| 91 | * @param list_head Á´±íÍ·½Úµã |
| 92 | * @param lan_info lÄÚÍøÐÄÏ¢ |
| 93 | * @note ÎÞ |
| 94 | */ |
| 95 | typedef struct LAN_INFO_LIST { |
| 96 | struct list_head list; |
| 97 | LAN_INFO_t lan_info; |
| 98 | } LAN_INFO_LIST_t; |
| 99 | |
| 100 | /** |
| 101 | * @brief dhcp server´æ´¢µÄleaseÎļþ½á¹¹Ìå |
| 102 | * @param expires expires |
| 103 | * @param ip ip µØÖ· |
| 104 | * @param mac mac µØÖ· |
| 105 | * @param host_nameÖ÷»úÃû |
| 106 | * @param pad |
| 107 | */ |
| 108 | typedef struct _DHCPOFFERADDRNET { |
| 109 | unsigned long expires; |
| 110 | unsigned long ip; |
| 111 | unsigned char mac[6]; |
| 112 | unsigned char host_name[20]; |
| 113 | unsigned char pad[2]; |
| 114 | } DHCPOFFERADDRNET; |
| 115 | |
| 116 | /** |
| 117 | * @brief dhcp ÐÅÏ¢Á´±í |
| 118 | * @param list Á´±íÍ·½Úµã |
| 119 | * @param dhcp_info dhcp ÐÅÏ¢ |
| 120 | */ |
| 121 | typedef struct _DHCPOFFERADDR_LIST { |
| 122 | struct list_head list; |
| 123 | DHCPOFFERADDRNET dhcp_info; |
| 124 | } DHCPOFFERADDR_LIST_t; |
| 125 | /** |
| 126 | * @brief dhcp gethostbynameÐÅÏ¢ |
| 127 | * @param time ³¬Ê±Ê±¼ä£¬µ¥Î»ÎªºÁÃë |
| 128 | * @param ¶ÓÁкŠ|
| 129 | */ |
| 130 | struct gethostbyname_info{ |
| 131 | int time; |
| 132 | char name[HOSTNAME_LEN]; |
| 133 | int msg_id; |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | /******************************************************************************* |
| 138 | * Global function declarations * |
| 139 | ******************************************************************************/ |
| 140 | |
| 141 | /** |
| 142 | * @brief ´Ódhcpd.leasesÎļþÖлñÈ¡dhcpÐÅÏ¢ |
| 143 | * @param dhcp_list_info dhcp ÐÅÏ¢Á´±í |
| 144 | * @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1 |
| 145 | */ |
| 146 | int zte_get_mac_list_from_lease(struct list_head *dhcp_list_info); |
| 147 | |
| 148 | /** |
| 149 | * @brief É豸ÐÅÏ¢ |
| 150 | * @param mypc_node É豸ÐÅÏ¢Á´±í |
| 151 | * @param info information |
| 152 | * @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1 |
| 153 | */ |
| 154 | int get_dev_list(struct pc_node* mypc_node); |
| 155 | |
| 156 | /** |
| 157 | * @brief ±£´æÐÅÏ¢µ½Îļþ |
| 158 | * @param filename ÎļþÃû |
| 159 | * @param info ÐèÒª±£´æµÄÐÅÏ¢ |
| 160 | * @return ÎÞ |
| 161 | */ |
| 162 | void save_file(char *filename, char* info); |
| 163 | |
| 164 | /** |
| 165 | * @brief дÐÅÏ¢µ½Îļþ |
| 166 | * @param filename ÎļþÃû |
| 167 | * @param info ÐèҪдµÄÐÅÏ¢ |
| 168 | * @return ÎÞ |
| 169 | */ |
| 170 | void file_write(char *filename, char *info); |
| 171 | |
| 172 | /** |
| 173 | * @brief ÊÍ·ÅdhcpÐÅÏ¢Á´±í |
| 174 | * @param dhcp_info_list dhcpÁ´±íÍ·½áµã |
| 175 | * @return ÎÞ |
| 176 | */ |
| 177 | void free_dhcp_list(struct list_head * dhcp_info_list); |
| 178 | |
| 179 | /** |
| 180 | * @brief ÊÍ·ÅÄÚÍøÐÅÏ¢Á´±í |
| 181 | * @param dhcp_info_list ÄÚÍøÐÅÏ¢Á´±íÍ·½áµã |
| 182 | * @return ÎÞ |
| 183 | */ |
| 184 | void free_laninfo_list(struct list_head * dhcp_info_list); |
| 185 | |
| 186 | /** |
| 187 | * @brief »ñÈ¡É豸ÐÅÏ¢ |
| 188 | * @param interface ÍøÂçÉ豸Ãû |
| 189 | * @param type Êý¾ÝÀàÐÍ |
| 190 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·Å»Ø-1 |
| 191 | */ |
| 192 | int getIfStatistic(char *interface, int type, unsigned long long *result_data); |
| 193 | |
| 194 | /** |
| 195 | * @brief »ñÈ¡wakelockËø |
| 196 | * @param lockId wakelockËøID |
| 197 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£» |
| 198 | */ |
| 199 | int set_wake_lock(const char *lockId); |
| 200 | |
| 201 | /** |
| 202 | * @brief »ñÈ¡wakelock³¬Ê±Ëø |
| 203 | * @param lockId wakelockËøID |
| 204 | * @param interval ³¬Ê±Ê±¼ä£¬µ¥Î»: Ãë |
| 205 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£» |
| 206 | */ |
| 207 | int set_wake_lock_timeout(const char *lockId, unsigned long interval); |
| 208 | |
| 209 | /** |
| 210 | * @brief ÊÍ·ÅwakelockËø |
| 211 | * @param lockId wakelockËøID |
| 212 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£» |
| 213 | */ |
| 214 | int set_wake_unlock(const char *lockId); |
| 215 | |
| 216 | |
| 217 | int get_lan_info_list(struct list_head *file_list_info); |
| 218 | |
| 219 | /** |
| 220 | * @brief ÉêÇëÄÚ´æ |
| 221 | * @param size ÉêÇëÄÚ´æ´óС |
| 222 | * @param is_assert£¬ÉêÇëʧ°ÜÊÇ·ñassert |
| 223 | * @return ÉêÇë³É¹¦·µ»ØÉêÇëÄÚ´æµØÖ·£»Ê§°Ü·µ»ØNULL |
| 224 | */ |
| 225 | void *safe_malloc(int size, BOOL is_assert); |
| 226 | |
| 227 | unsigned long time_sec(); |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * @brief »ñȡָ¶¨Ïß³ÌÃûµÄpidºÅ |
| 232 | * @param pidNameΪ½ø³ÌÃû |
| 233 | * @return ³É¹¦·µ»Ø½ø³ÌºÅpid_tÀàÐÍÖ¸Õë |
| 234 | * @note µ÷Óøú¯Êý»ñÈ¡·µ»ØÖµ£¬Ê¹ÓúóÒ»¶¨ÒªÊͷŸÃÄÚ´æ¿Õ¼ä |
| 235 | */ |
| 236 | pid_t* find_pid_by_name(char *pidName); |
| 237 | |
| 238 | /** |
| 239 | * @brief ¾ßÓг¬Ê±´¦ÀíµÄgethostbyname |
| 240 | * @param name url |
| 241 | * @param time ³¬Ê±Ê±³¤,µ¥Î»:Ãë, 0¾ÍÊDZê×¼µÄgethostbyname¹¦ÄÜ |
| 242 | * @return hostÐÅÏ¢ |
| 243 | * @Note: ͬһ½ø³ÌͬʱֻÄܵ÷ÓÃÒ»´Î¸Ã½Ó¿Ú |
| 244 | */ |
| 245 | struct hostent *gethostbyname_t(const char *name, int time); |
| 246 | |
| 247 | /** |
| 248 | * @±¾µØ¼¤»î»ñÈ¡dns½Ó¿Ú£¬²»ÒÀÀµÂ·ÓÉ£¬·µ»ØÖµÎªu32ÀàÐÍipµØÖ· |
| 249 | */ |
| 250 | unsigned long gethostbyname_l(char *hostname,char* dev_name); |
| 251 | |
| 252 | #endif |
| 253 | |
| 254 | #endif /* __NETOTHERAPI_H__ */ |