netmgr.h
浏览该文件的文档.
1 /*
2  * Copyright (C) 2019-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef NETMGR_H
6 #define NETMGR_H
7 #include <sys/socket.h>
8 #include <stdbool.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <uservice/uservice.h>
15 
22 typedef enum {
27 
29 typedef enum {
33 
34 #define IPADDR_STR_LEN 16
36 typedef struct netmgr_ifconfig_info {
37  bool dhcp_en;
42  char mac[IPADDR_STR_LEN + 1];
43  int rssi;
45 
46 #define NETMGR_SSID_MAX_LEN (32)
47 #define NETMGR_PWD_MAX_LEN (64)
48 #ifdef ETH_ALEN
49 #define NETMGR_BSSID_MAX_LEN (ETH_ALEN)
50 #else
51 #define NETMGR_BSSID_MAX_LEN (6)
52 #endif
53 
55 typedef enum {
59 
60 #define MAX_AP_CONFIG_NUM (3)
61 
63 typedef struct {
64  char ssid[NETMGR_SSID_MAX_LEN+1];
65  uint8_t pwd[NETMGR_PWD_MAX_LEN+1];
66  uint8_t bssid[NETMGR_BSSID_MAX_LEN];
67  int8_t ap_power;
68  uint8_t channel;
69  uint8_t sec_type;
72  char gbk_ssid[NETMGR_SSID_MAX_LEN+1];
74 
76 typedef struct {
77  int ap_num;
78  int used_ap;
81 
83 typedef enum {
91 
93 typedef enum {
102 
104 typedef enum {
112 
114 typedef struct netmgr_config {
116  union {
118  //netmgr_gprs_config_t gprs_config;
119  //netmgr_nbiot_config_t nbiot_config;
120  //netmgr_eth_config_t eth_config;
123 
125 typedef struct netmgr_del_config {
127  union {
131 
133 typedef struct netmgr_wifi_params {
135  void* params;
137 
139 typedef struct netmgr_wifi_ap_params {
143  char svr_ip[IPADDR_STRLEN_MAX];
144  char gw_ip[IPADDR_STRLEN_MAX];
145  char netmask_ip[IPADDR_STRLEN_MAX];
147  int hide;
149 
156  int timeout;
158 
160 typedef struct netmgr_connect_params {
162  union {
168 
169 #define NETMGR_WIFI_METHOD_MAX_LENGTH (32)
170 #define NETMGR_WIFI_STATUS_MAX_LENGTH (32)
171 #define NETMGR_WIFI_SSID_MAX_LENGTH (32)
172 #define NETMGR_WIFI_PASSWORD_MAX_LENGTH (64)
173 
175 typedef struct {
177  int quantity;
181  uint8_t reason_code;
183 
185 typedef struct {
187  union {
188  int status;
190  void *trace;
191  } data;
192 } netmgr_msg_t;
193 
195 typedef void (*netmgr_msg_cb_t)(netmgr_msg_t* msg);
196 
197 typedef int netmgr_hdl_t;
198 
200 typedef struct {
201  char ssid[NETMGR_SSID_MAX_LEN+1];
202  int8_t ap_power;
203  uint8_t bssid[NETMGR_BSSID_MAX_LEN];
204  uint8_t channel;
205  uint8_t sec_type;
207 
209 typedef enum netmgr_conn_state{
219 
227 int netmgr_service_init(utask_t *task);
228 
233 
241 int netmgr_add_dev(const char* name);
242 
250 netmgr_hdl_t netmgr_get_dev(const char* name);
251 
260 
270 
280 
288 
298 
307 
316 
325 
335 
345 
355 
365 
366 #ifdef AOS_NETWORK_WITH_WIFI
374 void* netmgr_wifi_get_netif(netmgr_hdl_t hdl);
375 
386 int netmgr_wifi_scan_result(netmgr_hdl_t hdl, netmgr_wifi_ap_list_t* ap_info, int num, netmgr_wifi_scan_type_t type);
387 
393 void netmgr_wifi_start_monitor(netmgr_hdl_t hdl);
394 
400 void netmgr_wifi_stop_monitor(netmgr_hdl_t hdl);
401 
407 void netmgr_wifi_start_mgnt_monitor(netmgr_hdl_t hdl);
408 
414 void netmgr_wifi_stop_mgnt_monitor(netmgr_hdl_t hdl);
415 
422 void netmgr_wifi_register_mgnt_monitor_cb(netmgr_hdl_t hdl, monitor_data_cb_t fn);
423 
433 int netmgr_wifi_send_80211_raw_frame(netmgr_hdl_t hdl, uint8_t *buf, int len);
434 #endif
435 
440 #ifdef __cplusplus
441 }
442 #endif
443 
444 #endif
445 
netmgr_ssid_format_e
ssid string format
Definition: netmgr.h:55
int netmgr_service_init(utask_t *task)
net manager init.
#define IPADDR_STR_LEN
Definition: netmgr.h:34
#define NETMGR_WIFI_PASSWORD_MAX_LENGTH
Definition: netmgr.h:172
eth_mac_duplex_e
ethernet duplex type
Definition: netmgr.h:29
int netmgr_add_dev(const char *name)
add netmgr dev
struct netmgr_ifconfig_info netmgr_ifconfig_info_t
this struct defines netmgr ifconfig info
int netmgr_connect(netmgr_hdl_t hdl, netmgr_connect_params_t *params)
netmgr connect network
void netmgr_service_deinit()
net manager deinit
netmgr_hdl_t netmgr_get_dev(const char *name)
get netmgr handler
#define NETMGR_WIFI_METHOD_MAX_LENGTH
Definition: netmgr.h:169
int netmgr_hdl_t
Definition: netmgr.h:197
struct netmgr_wifi_ap_config_t netmgr_wifi_config_t
int netmgr_save_config(netmgr_hdl_t hdl)
netmgr save config
void netmgr_set_auto_reconnect(netmgr_hdl_t hdl, bool enable)
set auto reconnect flag
netmgr_conn_state_t netmgr_get_state(netmgr_hdl_t hdl)
get state of hdl
netmgr_wifi_mode_t
netmgr wifi type
Definition: netmgr.h:104
netmgr_msgid_t
netmgr message type
Definition: netmgr.h:93
netmgr_conn_state
netmgr connection state
Definition: netmgr.h:209
void(* netmgr_msg_cb_t)(netmgr_msg_t *msg)
this struct defines netmgr message callback function
Definition: netmgr.h:195
#define NETMGR_PWD_MAX_LEN
Definition: netmgr.h:47
int netmgr_disconnect(netmgr_hdl_t hdl)
netmgr disconnect network
enum netmgr_conn_state netmgr_conn_state_t
netmgr connection state
#define MAX_AP_CONFIG_NUM
Definition: netmgr.h:60
struct netmgr_wifi_params netmgr_wifi_params_t
netmgr wifi params
int netmgr_set_ifconfig(netmgr_hdl_t hdl, netmgr_ifconfig_info_t *info)
set if config information
netmgr_type_t get_hdl_type(netmgr_hdl_t hdl)
get netmgr dev type
int netmgr_get_ifconfig(netmgr_hdl_t hdl, netmgr_ifconfig_info_t *info)
get if config information
int netmgr_del_msg_cb(netmgr_hdl_t hdl, netmgr_msg_cb_t cb)
netmgr delete message callback
int netmgr_get_config(netmgr_hdl_t hdl, netmgr_config_t *config)
get config information
int netmgr_del_config(netmgr_hdl_t, netmgr_del_config_t *config)
delete config information
struct netmgr_connect_params netmgr_connect_params_t
netmgr connect params
eth_mac_speed_e
ethernet speed type
Definition: netmgr.h:22
#define NETMGR_BSSID_MAX_LEN
Definition: netmgr.h:51
#define NETMGR_WIFI_SSID_MAX_LENGTH
Definition: netmgr.h:171
netmgr_type_t
network type
Definition: netmgr.h:83
int netmgr_set_msg_cb(netmgr_hdl_t hdl, netmgr_msg_cb_t cb)
netmgr set message callback
#define NETMGR_WIFI_STATUS_MAX_LENGTH
Definition: netmgr.h:170
struct netmgr_del_config netmgr_del_config_t
netmgr delete config
struct netmgr_wifi_ap_params netmgr_wifi_ap_params_t
netmgr wifi ap params
struct netmgr_config netmgr_config_t
netmgr config struct
#define NETMGR_SSID_MAX_LEN
Definition: netmgr.h:46
struct netmgr_wifi_sta_connect_params netmgr_wifi_sta_params_t
netmgr wifi sta connect params
@ NETMGR_SSID_FORMAT_GBK
Definition: netmgr.h:57
@ NETMGR_SSID_FORMAT_UTF8
Definition: netmgr.h:56
@ ETH_MAC_DUPLEX_HALF
Definition: netmgr.h:30
@ ETH_MAC_DUPLEX_FULL
Definition: netmgr.h:31
@ NETMGR_WIFI_MODE_APSTA
Definition: netmgr.h:107
@ NETMGR_WIFI_MODE_P2P
Definition: netmgr.h:108
@ NETMGR_WIFI_MODE_MAX
Definition: netmgr.h:110
@ NETMGR_WIFI_MODE_UNKNOWN
Definition: netmgr.h:109
@ NETMGR_WIFI_MODE_AP
Definition: netmgr.h:106
@ NETMGR_WIFI_MODE_STA
Definition: netmgr.h:105
@ NETMGR_MSGID_WIFI_STATUS_FROM_IMPL
Definition: netmgr.h:96
@ NETMGR_MSGID_MIN
Definition: netmgr.h:94
@ NETMGR_MSGID_ETH_STATUS_FROM_IMPL
Definition: netmgr.h:99
@ NETMGR_MSGID_WIFI_TRACE_FROM_IMPL
Definition: netmgr.h:97
@ NETMGR_MSGID_WIFI_STATUS
Definition: netmgr.h:95
@ NETMGR_MSGID_MAX
Definition: netmgr.h:100
@ NETMGR_MSGID_NETWORK_STATUS
Definition: netmgr.h:98
@ CONN_STATE_OBTAINING_IP
Definition: netmgr.h:214
@ CONN_STATE_CONNECTED
Definition: netmgr.h:213
@ CONN_STATE_UNKNOWN
Definition: netmgr.h:217
@ CONN_STATE_DISCONNECTED
Definition: netmgr.h:211
@ CONN_STATE_FAILED
Definition: netmgr.h:216
@ CONN_STATE_DISCONNECTING
Definition: netmgr.h:210
@ CONN_STATE_CONNECTING
Definition: netmgr.h:212
@ CONN_STATE_NETWORK_CONNECTED
Definition: netmgr.h:215
@ ETH_MAC_SPEED_1000M
Definition: netmgr.h:25
@ ETH_MAC_SPEED_100M
Definition: netmgr.h:24
@ ETH_MAC_SPEED_10M
Definition: netmgr.h:23
@ NETMGR_TYPE_UNKNOWN
Definition: netmgr.h:88
@ NETMGR_TYPE_WIFI
Definition: netmgr.h:84
@ NETMGR_TYPE_MAX
Definition: netmgr.h:89
@ NETMGR_TYPE_GPRS
Definition: netmgr.h:85
@ NETMGR_TYPE_NBIOT
Definition: netmgr.h:86
@ NETMGR_TYPE_ETH
Definition: netmgr.h:87
netmgr config struct
Definition: netmgr.h:114
netmgr_type_t type
Definition: netmgr.h:115
union netmgr_config::@0 config
netmgr_wifi_config_t wifi_config
Definition: netmgr.h:117
netmgr connect params
Definition: netmgr.h:160
netmgr_type_t type
Definition: netmgr.h:161
netmgr_wifi_ap_params_t ap_params
Definition: netmgr.h:165
netmgr_wifi_sta_params_t wifi_params
Definition: netmgr.h:164
union netmgr_connect_params::@2 params
netmgr_wifi_params_t wlan_params
Definition: netmgr.h:163
netmgr delete config
Definition: netmgr.h:125
netmgr_type_t type
Definition: netmgr.h:126
union netmgr_del_config::@1 config
char ssid[NETMGR_SSID_MAX_LEN+1]
Definition: netmgr.h:128
this struct defines netmgr ifconfig info
Definition: netmgr.h:36
char mask[IPADDR_STR_LEN]
Definition: netmgr.h:39
char gw[IPADDR_STR_LEN]
Definition: netmgr.h:40
char dns_server[IPADDR_STR_LEN]
Definition: netmgr.h:41
char ip_addr[IPADDR_STR_LEN]
Definition: netmgr.h:38
char mac[IPADDR_STR_LEN+1]
Definition: netmgr.h:42
this struct defines netmgr message
Definition: netmgr.h:185
void * trace
Definition: netmgr.h:190
int status
Definition: netmgr.h:188
netmgr_msgid_t id
Definition: netmgr.h:186
void * network_status_change
Definition: netmgr.h:189
this struct defines wifi ap config
Definition: netmgr.h:76
this struct defines wifi ap info
Definition: netmgr.h:63
uint8_t sec_type
Definition: netmgr.h:69
netmgr_ssid_format_e ssid_format
Definition: netmgr.h:71
this struct defines netmgr message callback function
Definition: netmgr.h:200
netmgr wifi ap params
Definition: netmgr.h:139
netmgr_wifi_mode_t mode
Definition: netmgr.h:140
char netmask_ip[IPADDR_STRLEN_MAX]
Definition: netmgr.h:145
char pwd[NETMGR_PWD_MAX_LEN+1]
Definition: netmgr.h:142
char ssid[NETMGR_SSID_MAX_LEN+1]
Definition: netmgr.h:141
char gw_ip[IPADDR_STRLEN_MAX]
Definition: netmgr.h:144
char svr_ip[IPADDR_STRLEN_MAX]
Definition: netmgr.h:143
this struct defines netmgr wifi status change info
Definition: netmgr.h:175
netmgr wifi params
Definition: netmgr.h:133
netmgr_wifi_mode_t mode
Definition: netmgr.h:134
netmgr wifi sta connect params
Definition: netmgr.h:151
netmgr_wifi_mode_t mode
Definition: netmgr.h:152
char pwd[NETMGR_PWD_MAX_LEN+1]
Definition: netmgr.h:154
char ssid[NETMGR_SSID_MAX_LEN+1]
Definition: netmgr.h:153
char bssid[NETMGR_BSSID_MAX_LEN]
Definition: netmgr.h:155