提交 024e3ea8 编写于 作者: M MurphyZhao 提交者: Bernard Xiong

[Fix] Fix issue caused by global info and local info in wlan/wlan_cmd.c

[Add] Change network_mode value according to the finsh shell command
上级 4dfabdcb
...@@ -41,8 +41,11 @@ struct rt_wlan_info info; ...@@ -41,8 +41,11 @@ struct rt_wlan_info info;
#define WIFI_SETTING_FN "/appfs/setting.json" #define WIFI_SETTING_FN "/appfs/setting.json"
#endif #endif
#ifndef WIFI_DEVICE_NAME #ifndef WIFI_DEVICE_STA_NAME
#define WIFI_DEVICE_NAME "w0" #define WIFI_DEVICE_STA_NAME "w0"
#endif
#ifndef WIFI_DEVICE_AP_NAME
#define WIFI_DEVICE_AP_NAME "ap"
#endif #endif
#ifdef RT_USING_DFS #ifdef RT_USING_DFS
...@@ -304,53 +307,43 @@ int wifi_default(void) ...@@ -304,53 +307,43 @@ int wifi_default(void)
/* read default setting for wifi */ /* read default setting for wifi */
wifi_read_cfg(WIFI_SETTING_FN); wifi_read_cfg(WIFI_SETTING_FN);
/* get wlan device */
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_NAME);
if (!wlan)
{
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_NAME);
return -1;
}
if (network_mode == WIFI_STATION) if (network_mode == WIFI_STATION)
{ {
struct rt_wlan_info *info; /* get wlan device */
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_STA_NAME);
info = (struct rt_wlan_info *)rt_malloc (sizeof(struct rt_wlan_info)); if (!wlan)
if (!info)
{ {
rt_kprintf("wifi: out of memory\n"); rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_STA_NAME);
return -1; return -1;
} }
/* wifi station */ /* wifi station */
rt_wlan_info_init(info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, wifi_ssid); rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, wifi_ssid);
result =rt_wlan_init(wlan, WIFI_STATION); result =rt_wlan_init(wlan, WIFI_STATION);
if (result == RT_EOK) if (result == RT_EOK)
{ {
result = rt_wlan_connect(wlan, info, wifi_key); result = rt_wlan_connect(wlan, &info, wifi_key);
} }
} }
else else
{ {
/* wifi AP */ /* wifi AP */
struct rt_wlan_info *info; /* get wlan device */
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_AP_NAME);
info = (struct rt_wlan_info *)rt_malloc (sizeof(struct rt_wlan_info)); if (!wlan)
if (!info)
{ {
rt_kprintf("wifi: out of memory\n"); rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_AP_NAME);
return -1; return -1;
} }
rt_wlan_info_init(info, WIFI_AP, SECURITY_WPA2_AES_PSK, wifi_ssid); rt_wlan_info_init(&info, WIFI_AP, SECURITY_WPA2_AES_PSK, wifi_ssid);
info->channel = 11; info.channel = 11;
/* wifi soft-AP */ /* wifi soft-AP */
result =rt_wlan_init(wlan, WIFI_AP); result =rt_wlan_init(wlan, WIFI_AP);
if (result == RT_EOK) if (result == RT_EOK)
{ {
result = rt_wlan_softap(wlan, info, wifi_key); result = rt_wlan_softap(wlan, &info, wifi_key);
} }
} }
...@@ -417,6 +410,7 @@ int wifi(int argc, char** argv) ...@@ -417,6 +410,7 @@ int wifi(int argc, char** argv)
if (strcmp(argv[2], "join") == 0) if (strcmp(argv[2], "join") == 0)
{ {
rt_wlan_init(wlan, WIFI_STATION); rt_wlan_init(wlan, WIFI_STATION);
network_mode = WIFI_STATION;
/* TODO: use easy-join to replace */ /* TODO: use easy-join to replace */
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]); rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]);
...@@ -471,34 +465,37 @@ int wifi(int argc, char** argv) ...@@ -471,34 +465,37 @@ int wifi(int argc, char** argv)
else if (strcmp(argv[2], "ap") == 0) else if (strcmp(argv[2], "ap") == 0)
{ {
rt_err_t result = RT_EOK; rt_err_t result = RT_EOK;
struct rt_wlan_info *info;
info = (struct rt_wlan_info*)rt_malloc(sizeof(struct rt_wlan_info));
if (argc == 4) if (argc == 4)
{ {
// open soft-AP // open soft-AP
rt_wlan_info_init(info, WIFI_AP, SECURITY_OPEN, argv[3]); rt_wlan_info_init(&info, WIFI_AP, SECURITY_OPEN, argv[3]);
info->channel = 11; info.channel = 11;
result =rt_wlan_init(wlan, WIFI_AP); result =rt_wlan_init(wlan, WIFI_AP);
/* start soft ap */ /* start soft ap */
result = rt_wlan_softap(wlan, info, NULL); result = rt_wlan_softap(wlan, &info, NULL);
if (result == RT_EOK)
{
network_mode = WIFI_AP;
}
} }
else if (argc == 5) else if (argc == 5)
{ {
// WPA2 with password // WPA2 with password
rt_wlan_info_init(info, WIFI_AP, SECURITY_WPA2_AES_PSK, argv[3]); rt_wlan_info_init(&info, WIFI_AP, SECURITY_WPA2_AES_PSK, argv[3]);
info->channel = 11; info.channel = 11;
result =rt_wlan_init(wlan, WIFI_AP); result =rt_wlan_init(wlan, WIFI_AP);
/* start soft ap */ /* start soft ap */
result = rt_wlan_softap(wlan, info, argv[4]); result = rt_wlan_softap(wlan, &info, argv[4]);
if (result == RT_EOK)
{
network_mode = WIFI_AP;
}
} }
else else
{ {
/* release information */
rt_free(info);
wifi_usage(); wifi_usage();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册