Пример #1
0
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();
		}
	}
}
Пример #2
0
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( );
}
Пример #3
0
int main(int argc, char *argv[])
{
	int rc = inetcfg_init();
	if (rc != EOK) {
		printf("%s: Failed connecting to inetcfg service (%d).\n",
		    NAME, rc);
		return 1;
	}
	
	rc = dhcp_init();
	if (rc != EOK) {
		printf("%s: Failed connecting to dhcp service (%d).\n",
		    NAME, rc);
		return 1;
	}
	
	if (argc == 2) {
		if (!str_cmp(argv[1], "list"))
			return wifi_list();
	} else if (argc > 2) {
		uint32_t index;
		rc = str_uint32_t(argv[2], NULL, 10, false, &index);
		if (rc != EOK) {
			printf("%s: Invalid argument.\n", NAME);
			print_syntax();
			return EINVAL;
		}
		
		if (!str_cmp(argv[1], "scan")) {
			bool now = false;
			if (argc > 3)
				if (!str_cmp(argv[3], "-n"))
					now = true;
			
			return wifi_scan(index, now);
		} else if (!str_cmp(argv[1], "connect")) {
			char *pass = NULL;
			if (argc > 3) {
				if (argc > 4)
					pass = argv[4];
				
				return wifi_connect(index, argv[3], pass);
			}
		} else if (!str_cmp(argv[1], "disconnect"))
			return wifi_disconnect(index);
	}
	
	print_syntax();
	
	return EOK;
}
Пример #4
0
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();
	}	
}
Пример #5
0
// 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");
	}
}
Пример #6
0
int wifi_entry(struct ftm_param *param, void *priv)
{
    char *ptr;
    int chosen;
    bool exit = false;
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    struct textview *tv;
    struct itemview *iv;
    int i = 0;
    int curStatus = -1; //disconnect

    LOGD(TAG "%s new\n", __FUNCTION__);

    memset(&wififm->info[0], 0, sizeof(wififm->info));
    memset(&wififm->info[0], '\n', 10);

    init_text(&wififm->title, param->name, COLOR_YELLOW);
    init_text(&wififm->text, &wififm->info[0], COLOR_YELLOW);

    if (!wififm->iv) {
        iv = ui_new_itemview();
        if (!iv) {
            LOGD(TAG "No memory for item view");
            return -1;
        }
        wififm->iv = iv;
    }

    iv = wififm->iv;
    iv->set_title(iv, &wififm->title);
    if(param->test_type == FTM_MANUAL_ITEM)
        iv->set_items(iv, wifi_items, 0);
    else
        iv->set_items(iv, wifi_auto_items, 0);
    iv->set_text(iv, &wififm->text);
    iv->start_menu(iv,0);

    iv->redraw(iv);
    LOGD(TAG "%s new2\n", __FUNCTION__);
    /*
        tv = &wififm->tv;
        ui_init_textview(tv, wifi_key_handler, (void*)wififm);
        tv->set(tv, "Wi-Fi", &wififm->info[0]);
        tv->set_btn(tv, "Fail", "Pass", "Back");
        tv->run(tv);
    */

    if(param->test_type == FTM_MANUAL_ITEM) //manual test
    {
        /* initialize thread condition */
        wififm->exit_thd = false;
        wififm->result = false;
        wififm->renew = true;
        pthread_create(&wififm->update_thd, NULL, wifi_update_thread, priv);

        do {
            chosen = iv->run(iv, &exit);
            switch (chosen) {
            case ITEM_RENEW:
                wififm->renew = true;
                break;

            case ITEM_PASS:
            case ITEM_FAIL:
                if (chosen == ITEM_PASS) {
                    wififm->mod->test_result = FTM_TEST_PASS;
                } else if (chosen == ITEM_FAIL) {
                    wififm->mod->test_result = FTM_TEST_FAIL;
                }

                exit = true;
                break;
            }

            if (exit) {
                wififm->exit_thd = true;
                break;
            }
        } while (1);
        pthread_join(wififm->update_thd, NULL);
    }
    else if(param->test_type == FTM_AUTO_ITEM)  //auto test
    {
        if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
            LOGE("[WIFI][FTM_AUTO_ITEM] FM_WIFI_init failed!\n");
            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_init_fail);
            iv->redraw(iv);
            return -1;
        }

        while(i++ < 3) {
            //1. disconnect the connection.
            wifi_disconnect();

            //2. connect to the AP.
            if(wifi_fm_test() < 0 ) {
                LOGD("[WIFI][FTM_AUTO_ITEM] wifi_fm_test failed!\n");
            } else {
                int count =10;
                iv->redraw(iv);
                while(count-- >0) {
                    /*                    if (wififm->exit_thd || wififm->renew)
                                        break;	 */
                    if(wifi_update_status() < 0) {
                        if(count)
                            usleep(100000);
                        else {
                            memset(wififm->info,0, sizeof(wififm->info));
                            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_timeout);
                        }
                    } else {
                        curStatus = 1;  //connected
                        //show the message
                    }
                    iv->redraw(iv);
                }
            }

            //3. check the status
            if(curStatus == 1) {
                wififm->mod->test_result = FTM_TEST_PASS;
                LOGD(TAG "while %d connected\n", i);
                break;
            }
        }

        if(3 == i) {
            wififm->mod->test_result = FTM_TEST_FAIL;
            LOGD(TAG "while i == 3\n", i);
        }

    }
    else if (param->test_type == FTM_ASYN_ITEM)
    {
        LOGD(TAG "param->test_type == FTM_ASYN_ITEM\n");
        pthread_create(&wififm->update_thd, NULL, wifi_update_thread_test, priv);
        //if(3 == param->test_type)
        {
            //pthread_join(wififm->update_thd, NULL);
        }
    }

    if (param->test_type != FTM_ASYN_ITEM)
    {
        FM_WIFI_deinit();
    }

    return 0;
}
Пример #7
0
static void *wifi_update_thread_test(void *priv)
{
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    struct textview *tv;
    struct itemview *iv;
    int i = 0;
    iv = wififm->iv;
    char wifi_result[32] = {0};

    int curStatus = -1; //disconnect

    if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
        LOGE("[WIFI] FM_WIFI_init failed!\n");
        sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_init_fail);
        iv->redraw(iv);
        sprintf(wifi_result, "%d:%s", wififm->mod->id, result[FTM_TEST_FAIL]);
        LOGD(TAG "WIFI result:%s", wifi_result);
        write_data_to_pc(wifi_result, strlen(wifi_result));
        return NULL;
    }

    while(i++ < 3) {
        //1. disconnect the connection.
        wifi_disconnect();

        //2. connect to the AP.
        if(wifi_fm_test() > 0) {
            LOGD("[WIFI][wifi_update_thread_test] wifi_fm_test failed!\n");
        } else {
            int count =10;
            iv->redraw(iv);
            while(count-- >0) {
                /*                    if (wififm->exit_thd || wififm->renew)
                                    break;   */
                if(wifi_update_status() < 0) {
                    if(count)
                        usleep(100000);
                    else {
                        memset(wififm->info,0, sizeof(wififm->info));
                        sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_timeout);
                    }
                } else {
                    curStatus = 1;  //connected
                    //show the message
                }
                iv->redraw(iv);
            }
        }

        //3. check the status
        if(curStatus == 1) {
            wififm->mod->test_result = FTM_TEST_PASS;
            LOGD(TAG "while %d connected\n", i);
            break;
        }
    }

    if(3 == i) {
        wififm->mod->test_result = FTM_TEST_FAIL;
        LOGD(TAG "while i == 3\n", i);
    }

    FM_WIFI_deinit();
    LOGD(TAG "wififm->mod->id:%d; wififm->mod->test_result:%d", wififm->mod->id, wififm->mod->test_result);
    //if(get_is_ata())
    {
        sprintf(wifi_result, "%d:%s", wififm->mod->id, result[wififm->mod->test_result]);
        LOGD(TAG "WIFI result:%s", wifi_result);
        write_data_to_pc(wifi_result, strlen(wifi_result));
    }

    return NULL;
}