#ifdef WCLIENT //#include //#include //#include //#include #include #include //#include #include #include #define WIF "eth2" extern int wl_ioctl(char *name, int request, void *buf, int len); extern SITES sites_g[]; extern int sites_g_count; extern PROFILES profiles_g[]; extern int profiles_g_count; extern int scan_g_mode; extern int scan_g_type; uint8 buf[4096]; time_t scantime=0; int wl_scan_disabled=0; int wl_scan(char *ssid) { int ret, unit; time_t now; time(&now); //printf("scan %x %x %x\n", (unsigned int)scantime, (unsigned int)now, (unsigned int)(now-scantime)); if ((unsigned int )(now-scantime) > 10 && !wl_scan_disabled) { //printf("scan actually\n"); unit = 0; ret=wl_ioctl(WIF, WLC_SET_AP, &unit, sizeof(unit)); ret=wl_ioctl(WIF, WLC_SCAN, &unit, sizeof(unit)); memcpy(&scantime, &now, sizeof(time_t)); } return ret; } int wl_scan_results(void) { int unit, ret, i, j; wl_scan_results_t *result; wl_bss_info_t *info; char *info_b; unsigned char *ie; result = (wl_scan_results_t *)buf; result->buflen=sizeof(buf); result->version=WL_BSS_INFO_VERSION; ret=wl_ioctl(WIF, WLC_SCAN_RESULTS, result, sizeof(buf)); if (ret==0) { //printf("count: %x %x %d %d\n", result->count, result->version, sizeof(wl_bss_info_t), sizeof(wl_bss_info106_t)); info = &(result->bss_info[0]); info_b = (unsigned char *)info; for(i=0;i<512;i++) if (info_b[i] == 107) printf("i=%d\n", i); for(i=0;icount;i++) { //printf("VER : %d\n", info->version); //printf("Ssid : %s\n", info->SSID); //printf("Channel : %d\n", info->channel); //printf("RSSI : %d\n", info->RSSI); //printf("Noise : %d\n", info->phy_noise); //printf("Cap : %x\n", info->capability); //printf("IE: : %d %d\n", sizeof(wl_bss_info_t), info->ie_length); memcpy(sites_g[i].SSID, info->SSID, 32); sites_g[i].Type = 0; sites_g[i].Channel = info->channel; sites_g[i].Wep = 0; sites_g[i].Status = 0; memcpy(sites_g[i].BSSID, &info->BSSID, 6); sites_g[i].RSSI = info->RSSI; ie = &info->ie_length + 1; j=0; while(jie_length) { //printf("IE: %x %x\n", (unsigned char)ie[j], ie[j+1]); if (ie[j] == 0xdd) { //printf("WEP\n"); sites_g[i].Wep = 1; } j+=ie[j+1] + 2; } //assign to profile info_b += (sizeof(wl_bss_info_t)); if ((info->ie_length%4)) { info_b+=info->ie_length+4-(info->ie_length%4); } else info_b+=info->ie_length; info = (wl_bss_info_t *)info_b; } sites_g_count = result->count; return (sites_g_count); } return 0; } int wl_isap(void) { int val; wl_ioctl(WIF, WLC_GET_AP, &val, sizeof(val)); return val; } int wl_status(PROFILES *profile) { int unit, ret, i; char bssid[32]; char bssinfobuf[2000]; wl_bss_info_t *info; int val; // Get bssid ret=wl_ioctl(WIF, WLC_GET_BSSID, bssid, sizeof(bssid)); //wl_scan_results(); if (ret==0 && !(bssid[0]==0&&bssid[1]==0&&bssid[2]==0 &&bssid[3]==0&&bssid[4]==0&&bssid[5]==0)) { //printf("Found\n"); ret=wl_ioctl(WIF, WLC_GET_BSS_INFO, bssinfobuf, sizeof(bssinfobuf)); info = (wl_bss_info_t *)bssinfobuf; //if (ret==0) printf("Connect to : %s\n", info->SSID); //else printf("Connect to unknown\n"); return 1; } return 0; } void wl_connect(PROFILES *profile) { wsec_key_t key; char *keystr, hex[3]; unsigned char *data=key.data; wlc_ssid_t ssid; int val, i; if (profile->mode == STATION_MODE_AP) { // Set driver to AP mode val = 1; wl_ioctl(WIF, WLC_SET_AP, &val, sizeof(val)); // Set to Infra val = 1; wl_ioctl(WIF, WLC_SET_INFRA, &val, sizeof(val)); } else { // Set driver to Sta mode val = 0; wl_ioctl(WIF, WLC_SET_AP, &val, sizeof(val)); // Set station mode if (profile->mode == STATION_MODE_INFRA) val = 1; else val=0; wl_ioctl(WIF, WLC_SET_INFRA, &val, sizeof(val)); if (nvram_invmatch("wlp_clientmode_x", "2")) val=0; else val=1; wl_ioctl(WIF, WLC_SET_WET, &val, sizeof(val)); } // Set Authentication mode val = profile->sharedkeyauth; //printf("auth: %d\n", val); wl_ioctl(WIF, WLC_SET_AUTH, &val, sizeof(val)); // Set WEP enable if (profile->wep == STA_ENCRYPTION_ENABLE) { //printf("wep: %d %d\n", profile->wep, profile->wepkeylen); // Set WEP key for(i=0;i<4;i++) { memset(&key, 0, sizeof(wsec_key_t)); key.index = i; if (i==0) keystr = profile->wepkey1; else if (i==1) keystr = profile->wepkey2; else if (i==2) keystr = profile->wepkey3; else if (i==3) keystr = profile->wepkey4; if (profile->wepkeylen==STA_ENCRYPTION_TYPE_WEP64) { key.algo = CRYPTO_ALGO_WEP1; key.len=5; } else { key.algo = CRYPTO_ALGO_WEP128; key.len=13; } strncpy(key.data, keystr, key.len); //printf("%x %x %x\n", key.data[0], key.data[1], key.len); if (i==profile->wepkeyactive) key.flags=WSEC_PRIMARY_KEY; wl_ioctl(WIF, WLC_SET_KEY, &key, sizeof(key)); } //val = WEP_ENABLED; val = 1; } else val = 0; //wl_ioctl(WIF, WLC_SET_WSEC, &val, sizeof(val)); For AP? wl_ioctl(WIF, WLC_SET_WEP, &val, sizeof(val)); memset(&ssid, 0, sizeof(ssid)); ssid.SSID_len = strlen(profile->ssid); strncpy(ssid.SSID, profile->ssid, ssid.SSID_len); wl_ioctl(WIF, WLC_SET_SSID, &ssid, sizeof(ssid)); } void wl_join(PROFILES *profile) { int unit, ret, i; wl_scan_results_t *result; wl_bss_info_t *info; // get scan result // check if ssid in this list, if yes, connect it // if ssid is not in the list, connect any one profile wl_connect(profile); } void wl_disassoc(void) { } char *nvram_get_str(char *name, int index) { char tmpname[32], tmpval[64]; if (index!=-1) sprintf(tmpname, "%s%d", name, index); else sprintf(tmpname, "%s", name); return(nvram_safe_get(tmpname)); } int nvram_get_val(char *name, int index) { char tmpname[32], tmpval[64]; if (index!=-1) sprintf(tmpname, "%s%d", name, index); else sprintf(tmpname, "%s", name); return(atoi(nvram_safe_get(tmpname))); } void wl_read_profile(void) { int i, weptype; profiles_g_count = nvram_get_val("wlp_num", -1); scan_g_type = nvram_get_val("wlp_scan_type", -1); scan_g_mode = nvram_get_val("wlp_scan_mode", -1); printf("count: %d\n", profiles_g_count); for(i=0;i0) { nvram_set("st_toolstatus_t", "proceeding"); nvram_set("st_tool_t", ""); system(cmd); } } #endif