1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4 #ifndef AOS_BOARD_HAAS700
5 #include "amp_platform.h"
6 #include "aos_network.h"
7 #include "netmgr.h"
8 #include "netmgr_wifi.h"
9
10 #define WIFI_DEV_PATH "/dev/wifi0"
11
aos_wifi_init()12 int aos_wifi_init()
13 {
14 return netmgr_service_init(NULL);
15 }
16
17
aos_wifi_set_ifconfig(netmgr_ifconfig_info_t * info)18 int aos_wifi_set_ifconfig(netmgr_ifconfig_info_t *info)
19 {
20 netmgr_hdl_t hdl;
21
22 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
23 return -1;
24 }
25 return netmgr_set_ifconfig(hdl, info);
26 }
27
aos_wifi_get_ifconfig(netmgr_ifconfig_info_t * info)28 int aos_wifi_get_ifconfig(netmgr_ifconfig_info_t *info)
29 {
30 netmgr_hdl_t hdl;
31
32 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
33 return -1;
34 }
35 return netmgr_get_ifconfig(hdl, info);
36 }
37
aos_wifi_set_msg_cb(netmgr_msg_cb_t cb)38 int aos_wifi_set_msg_cb(netmgr_msg_cb_t cb)
39 {
40 netmgr_hdl_t hdl;
41
42 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
43 return -1;
44 }
45 return netmgr_set_msg_cb(hdl, cb);
46 }
47
aos_wifi_del_msg_cb(netmgr_msg_cb_t cb)48 int aos_wifi_del_msg_cb(netmgr_msg_cb_t cb)
49 {
50 netmgr_hdl_t hdl;
51
52 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
53 return -1;
54 }
55 return netmgr_del_msg_cb(hdl, cb);
56 }
57
aos_get_network_type()58 AOS_NETWORK_TYPE_E aos_get_network_type()
59 {
60 return AOS_NETWORK_WIFI;
61 }
62
aos_wifi_connect(const char * ssid,const char * passwd)63 int aos_wifi_connect(const char *ssid, const char *passwd)
64 {
65 int ret = -1;
66 netmgr_hdl_t hdl;
67 netmgr_connect_params_t params;
68
69 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
70 return -1;
71 }
72
73 memset(¶ms, 0, sizeof(netmgr_connect_params_t));
74 params.type = NETMGR_TYPE_WIFI;
75 strncpy(params.params.wifi_params.ssid, ssid, sizeof(params.params.wifi_params.ssid) - 1);
76 strncpy(params.params.wifi_params.pwd, passwd, sizeof(params.params.wifi_params.pwd) - 1);
77 params.params.wifi_params.timeout = 60000;
78
79 ret = netmgr_connect(hdl, ¶ms);
80 if (ret != 0) {
81 return ret;
82 }
83
84 return ret;
85 }
86
aos_get_wifi_info(aos_wifi_info_t * wifi_info)87 int aos_get_wifi_info(aos_wifi_info_t *wifi_info)
88 {
89 netmgr_hdl_t hdl;
90 netmgr_config_t config;
91 netmgr_ifconfig_info_t info;
92 int ap_num;
93 int used_ap; /**< ap that is used in the array */
94
95 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
96 return -1;
97 }
98
99 memset(&info, 0, sizeof(info));
100 if(netmgr_get_ifconfig(hdl, &info) == -1) {
101 return -1;
102 }
103
104 memset(&config, 0, sizeof(config));
105 if(netmgr_get_config(hdl, &config) == -1) {
106 return -1;
107 }
108 ap_num = config.config.wifi_config.ap_num;
109 used_ap = config.config.wifi_config.used_ap;
110
111 if((ap_num < MAX_AP_CONFIG_NUM) && (used_ap < ap_num)) {
112 memset(wifi_info->ssid, 0, sizeof(wifi_info->ssid));
113 strncpy(wifi_info->ssid, config.config.wifi_config.config[used_ap].ssid, sizeof(wifi_info->ssid) - 1);
114 } else {
115 return -1;
116 }
117
118 snprintf(wifi_info->ip, sizeof(wifi_info->ip), "%s", info.ip_addr);
119 memcpy(wifi_info->mac, info.mac, sizeof(wifi_info->mac));
120 wifi_info->rssi = info.rssi;
121
122 return 0;
123 }
124
aos_wifi_disconnect()125 int aos_wifi_disconnect()
126 {
127 netmgr_hdl_t hdl;
128
129 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
130 return -1;
131 }
132 return netmgr_disconnect(hdl);
133 }
134
aos_wifi_get_state()135 int aos_wifi_get_state()
136 {
137 netmgr_hdl_t hdl;
138
139 if((hdl = netmgr_get_dev(WIFI_DEV_PATH)) == -1) {
140 return -1;
141 }
142 return netmgr_get_state(hdl);
143 }
144 #endif
145