void fATWD(void *arg){ int timeout = 20; char essid[33]; printf("[ATWD]: _AT_WLAN_DISC_NET_\n\r"); printf("\n\rDeassociating AP ..."); if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { printf("\n\rWIFI disconnected"); return; } if(wifi_disconnect() < 0) { printf("\n\rERROR: Operation failed!"); return; } while(1) { if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { printf("\n\rWIFI disconnected"); break; } if(timeout == 0) { printf("\n\rERROR: Deassoc timeout!"); break; } vTaskDelay(1 * configTICK_RATE_HZ); timeout --; } printf("\n\r"); init_wifi_struct( ); }
void wifi_enter_promisc_mode(){ int mode = 0; unsigned char ssid[33]; if(wifi_mode == RTW_MODE_STA_AP){ wifi_off(); vTaskDelay(20); wifi_on(RTW_MODE_PROMISC); }else{ wext_get_mode(WLAN0_NAME, &mode); switch(mode) { case IW_MODE_MASTER: //In AP mode //rltk_wlan_deinit(); wifi_off();//modified by Chris Yang for iNIC vTaskDelay(20); //rltk_wlan_init(0, RTW_MODE_PROMISC); //rltk_wlan_start(0); wifi_on(RTW_MODE_PROMISC); break; case IW_MODE_INFRA: //In STA mode if(wext_get_ssid(WLAN0_NAME, ssid) > 0) wifi_disconnect(); } } }
int rthw_wifi_ap_start(char *ssid, char *password, int channel) { int mode = 0, timeout = 20; rtw_security_t security_type = RTW_SECURITY_WPA2_AES_PSK; char *name = RT_NULL; mode = rthw_wifi_mode_get(); if (mode == RTHW_MODE_AP) { name = WLAN0_NAME; } else if (mode == RTHW_MODE_STA_AP) { name = WLAN1_NAME; } else { return -1; } if(wext_get_mode(name, &mode) < 0) { rt_kprintf("L:%d wifi get mode err\n", __LINE__); return -1; } if (password == RT_NULL) { security_type = RTW_SECURITY_OPEN; } if(wifi_start_ap(ssid, security_type, password, rt_strlen(ssid), rt_strlen(password), 6) != 0) { rt_kprintf("ERROR: wifi_start_ap failed\n"); return -1; } while(1) { char essid[33]; if(wext_get_ssid(name, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)ssid) == 0) { rt_kprintf("%s started\n", ssid); break; } } if(timeout == 0) { rt_kprintf("Start AP timeout\n"); return -1; } rt_thread_delay(1 * RT_TICK_PER_SECOND); timeout --; } return 0; }
//----------------------------------------------------------------------------// int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting) { int ret = 0; int mode = 0; unsigned short security = 0; memset(pSetting, 0, sizeof(rtw_wifi_setting_t)); if(wext_get_mode(ifname, &mode) < 0) ret = -1; switch(mode) { case IW_MODE_MASTER: pSetting->mode = RTW_MODE_AP; break; case IW_MODE_INFRA: default: pSetting->mode = RTW_MODE_STA; break; //default: //printf("\r\n%s(): Unknown mode %d\n", __func__, mode); //break; } if(wext_get_ssid(ifname, pSetting->ssid) < 0) ret = -1; if(wext_get_channel(ifname, &pSetting->channel) < 0) ret = -1; if(wext_get_enc_ext(ifname, &security, &pSetting->key_idx, pSetting->password) < 0) ret = -1; switch(security){ case IW_ENCODE_ALG_NONE: pSetting->security_type = RTW_SECURITY_OPEN; break; case IW_ENCODE_ALG_WEP: pSetting->security_type = RTW_SECURITY_WEP_PSK; break; case IW_ENCODE_ALG_TKIP: pSetting->security_type = RTW_SECURITY_WPA_TKIP_PSK; break; case IW_ENCODE_ALG_CCMP: pSetting->security_type = RTW_SECURITY_WPA2_AES_PSK; break; default: break; } if(security == IW_ENCODE_ALG_TKIP || security == IW_ENCODE_ALG_CCMP) if(wext_get_passphrase(ifname, pSetting->password) < 0) ret = -1; return ret; }
static int rthw_wifi_disconnect(char *name) { char essid[33]; int timeout = 20; const rt_uint8_t null_bssid[ETH_ALEN + 2] = {0, 0, 0, 0, 0, 1, 0, 0}; if (name == RT_NULL) return -1; if (wext_get_ssid(name, (unsigned char *) essid) < 0) { rt_kprintf("\nWIFI disconnected!\n"); return -1; } if (wext_set_bssid(name, null_bssid) < 0) { rt_kprintf("Failed to set bogus BSSID to disconnect"); return -1; } while (1) { if(wext_get_ssid(name, (unsigned char *) essid) < 0) { rt_kprintf("WIFI disconnected!\n"); break; } if(timeout == 0) { rt_kprintf("ERROR: Deassoc timeout!\n"); return -1; } rt_thread_delay(10); timeout --; } return 0; }
int nl80211_get_ssid(const char *ifname, char *buf) { char *ssid; if (!wext_get_ssid(ifname, buf)) { return 0; } else if( (ssid = nl80211_hostapd_info(ifname)) && (ssid = nl80211_getval(ifname, ssid, "ssid")) ) { memcpy(buf, ssid, strlen(ssid)); return 0; } return -1; }
void wps_judge_staion_disconnect(void) { int mode = 0; unsigned char ssid[33]; wext_get_mode(WLAN0_NAME, &mode); switch(mode) { case IW_MODE_MASTER: //In AP mode rltk_wlan_deinit(); rltk_wlan_init(0,RTW_MODE_STA); rltk_wlan_start(0); break; case IW_MODE_INFRA: //In STA mode if(wext_get_ssid(WLAN0_NAME, ssid) > 0) wifi_disconnect(); } }
int madwifi_get_ssid(const char *ifname, char *buf) { return wext_get_ssid(ifname, buf); }
// For BCT hut-plugging test void cmd_interface(int argc, char **argv) { if(argc == 1) goto error; if(strcmp(argv[1], "set") == 0) { if((argc == 4) || (argc == 5)) { struct ip_addr ip_addr; struct ip_addr netmask_addr; struct ip_addr gw_addr; uint32_t ip[4], netmask[4], gw[4]; char *ptr, *head, *tail; int i; ptr = argv[2]; for(i = 0; i < 4; i ++) { head = ptr; while(*ptr && *ptr != '.') ptr ++; tail = ptr ++; *tail = 0; ip[i] = atoi(head); } ptr = argv[3]; for(i = 0; i < 4; i ++) { head = ptr; while(*ptr && *ptr != '.') ptr ++; tail = ptr ++; *tail = 0; netmask[i] = atoi(head); } if(argc == 5) { ptr = argv[4]; for(i = 0; i < 4; i ++) { head = ptr; while(*ptr && *ptr != '.') ptr ++; tail = ptr ++; *tail = 0; gw[i] = atoi(head); } } else { memset(gw, 0, sizeof(gw)); } IP4_ADDR(&ip_addr, ip[0], ip[1], ip[2], ip[3]); IP4_ADDR(&netmask_addr, netmask[0], netmask[1], netmask[2], netmask[3]); IP4_ADDR(&gw_addr, gw[0], gw[1], gw[2], gw[3]); netif_set_addr(&xnetif[0], &ip_addr , &netmask_addr, &gw_addr); printf("\nSet IP : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); printf( " MASK: %d.%d.%d.%d\n", netmask[0], netmask[1], netmask[2], netmask[3]); printf( " GW : %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]); } else { printf("Usage: interface set IP NETMASK [GATEWAY]\n"); } } else if(strcmp(argv[1], "info") == 0) { u8 *mac = LwIP_GetMAC(&xnetif[0]); u8 *ip = LwIP_GetIP(&xnetif[0]); u8 *netmask = LwIP_GetMASK(&xnetif[0]); u8 *gw = LwIP_GetGW(&xnetif[0]); printf("\n MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); printf("\nIPv4 Address : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); printf( " Netmask : %d.%d.%d.%d\n", netmask[0], netmask[1], netmask[2], netmask[3]); printf( " Gateway : %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]); #if LWIP_IPV6 uint8_t *ipv6 = (uint8_t *) &(xnetif[0].ip6_addr[0].addr[0]); printf("\nIPv6 Address : %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5], ipv6[6], ipv6[7], ipv6[8], ipv6[9], ipv6[10], ipv6[11], ipv6[12], ipv6[13], ipv6[14], ipv6[15]); #endif } else if(strcmp(argv[1], "disconnect") == 0) { int timeout = 20; char essid[33]; if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { printf("\nWIFI disconnected\n"); return; } wifi_disconnect(); while(1) { if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { printf("\nWIFI disconnected\n"); break; } if(timeout == 0) { printf("\nERROR: Operation failed!\n"); break; } vTaskDelay(1000); timeout --; } } else if(strcmp(argv[1], "reconnect") == 0) { HomeKitNetworkConnection(); } else { error: printf("Usage: interface set|info|disconnect|reconnect\n"); } }
void fATWB(void *arg) { int timeout = 20;//, mode; #if CONFIG_LWIP_LAYER struct netif * pnetiff = (struct netif *)&xnetif[1]; #endif printf("[ATWB](_AT_WLAN_AP_STA_ACTIVATE_)\n\r"); if(ap.ssid.val[0] == 0){ printf("[ATWB]Error: SSID can't be empty\n\r"); return; } if(ap.channel > 14){ printf("[ATWB]Error:bad channel! channel is from 1 to 14\n\r"); return; } if(ap.password == NULL){ ap.security_type = RTW_SECURITY_OPEN; } else{ ap.security_type = RTW_SECURITY_WPA2_AES_PSK; } #if CONFIG_LWIP_LAYER dhcps_deinit(); #endif wifi_off(); vTaskDelay(20); if (wifi_on(RTW_MODE_STA_AP) < 0){ printf("\n\rERROR: Wifi on failed!"); return; } printf("\n\rStarting AP ..."); if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) { printf("\n\rERROR: Operation failed!"); return; } while(1) { char essid[33]; if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) { printf("\n\r%s started\n", ap.ssid.val); break; } } if(timeout == 0) { printf("\n\rERROR: Start AP timeout!"); break; } vTaskDelay(1 * configTICK_RATE_HZ); timeout --; } #if CONFIG_LWIP_LAYER LwIP_UseStaticIP(&xnetif[1]); #ifdef CONFIG_DONT_CARE_TP pnetiff->flags |= NETIF_FLAG_IPSWITCH; #endif dhcps_init(pnetiff); #endif }
void fATWA(void *arg){ #if CONFIG_LWIP_LAYER struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; struct netif * pnetif = &xnetif[0]; #endif int timeout = 20; printf("[ATWA]: _AT_WLAN_AP_ACTIVATE_\n\r"); if(ap.ssid.val[0] == 0){ printf("[ATWA]Error: SSID can't be empty\n\r"); return; } if(ap.password == NULL){ ap.security_type = RTW_SECURITY_OPEN; } else{ ap.security_type = RTW_SECURITY_WPA2_AES_PSK; } #if CONFIG_WEBSERVER //store into flash memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));; memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val)); wifi_setting.ssid[ap.ssid.len] = '\0'; wifi_setting.security_type = ap.security_type; if(ap.security_type !=0) wifi_setting.security_type = 1; else wifi_setting.security_type = 0; if (ap.password) memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password)); else memset(wifi_setting.password, 0, sizeof(wifi_setting.password));; wifi_setting.channel = ap.channel; #if CONFIG_READ_FLASH StoreApInfo(); #endif #endif #if CONFIG_LWIP_LAYER dhcps_deinit(); IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(pnetif, &ipaddr, &netmask,&gw); #ifdef CONFIG_DONT_CARE_TP pnetif->flags |= NETIF_FLAG_IPSWITCH; #endif #endif wifi_off(); vTaskDelay(20); if (wifi_on(RTW_MODE_AP) < 0){ printf("\n\rERROR: Wifi on failed!"); return; } printf("\n\rStarting AP ..."); #ifdef CONFIG_WPS_AP wpas_wps_dev_config(pnetif->hwaddr, 1); #endif if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) { printf("\n\rERROR: Operation failed!"); return; } while(1) { char essid[33]; if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) { printf("\n\r%s started\n", ap.ssid.val); break; } } if(timeout == 0) { printf("\n\rERROR: Start AP timeout!"); break; } vTaskDelay(1 * configTICK_RATE_HZ); timeout --; } #if CONFIG_LWIP_LAYER //LwIP_UseStaticIP(pnetif); dhcps_init(pnetif); #endif init_wifi_struct( ); }