static int wl_cfgnan_parse_args(char *buf, nan_cmd_data_t *cmd_data) { s32 ret = BCME_OK; char *token = buf; char delim[] = " "; while ((buf != NULL) && (token != NULL)) { if (!strncmp(buf, PUB_ID_PREFIX, strlen(PUB_ID_PREFIX))) { buf += strlen(PUB_ID_PREFIX); token = strsep(&buf, delim); cmd_data->pub_id = simple_strtoul(token, NULL, 10); if (INVALID_ID(cmd_data->pub_id)) { WL_ERR((" invalid publisher id, pub_id = %d \n", cmd_data->pub_id)); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, SUB_ID_PREFIX, strlen(SUB_ID_PREFIX))) { buf += strlen(SUB_ID_PREFIX); token = strsep(&buf, delim); cmd_data->sub_id = simple_strtoul(token, NULL, 10); if (INVALID_ID(cmd_data->sub_id)) { WL_ERR((" invalid subscriber id, sub_id = %d \n", cmd_data->sub_id)); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, MAC_ADDR_PREFIX, strlen(MAC_ADDR_PREFIX))) { buf += strlen(MAC_ADDR_PREFIX); token = strsep(&buf, delim); if (!wl_cfg80211_ether_atoe(token, &cmd_data->mac_addr)) { WL_ERR((" invalid mac address, mac_addr = "MACDBG "\n", MAC2STRDBG(cmd_data->mac_addr.octet))); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, SVC_HASH_PREFIX, strlen(SVC_HASH_PREFIX))) { buf += strlen(SVC_HASH_PREFIX); token = strsep(&buf, delim); cmd_data->svc_hash.data = token; cmd_data->svc_hash.dlen = WL_NAN_SVC_HASH_LEN; } else if (!strncmp(buf, SVC_INFO_PREFIX, strlen(SVC_INFO_PREFIX))) { buf += strlen(SVC_INFO_PREFIX); token = strsep(&buf, delim); cmd_data->svc_info.data = token; cmd_data->svc_info.dlen = strlen(token); } else if (!strncmp(buf, CHAN_PREFIX, strlen(CHAN_PREFIX))) { buf += strlen(CHAN_PREFIX); token = strsep(&buf, delim); cmd_data->chanspec = wf_chspec_aton(token); cmd_data->chanspec = wl_chspec_host_to_driver(cmd_data->chanspec); if (INVALID_CHANSPEC(cmd_data->chanspec)) { WL_ERR((" invalid chanspec, chanspec = 0x%04x \n", cmd_data->chanspec)); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, BITMAP_PREFIX, strlen(BITMAP_PREFIX))) { buf += strlen(BITMAP_PREFIX); token = strsep(&buf, delim); cmd_data->bmap = simple_strtoul(token, NULL, 16); } else if (!strncmp(buf, ATTR_PREFIX, strlen(ATTR_PREFIX))) { buf += strlen(ATTR_PREFIX); token = strsep(&buf, delim); if (!wl_cfgnan_config_attr(token, &cmd_data->attr)) { WL_ERR((" invalid attribute, attr = %s \n", cmd_data->attr.name)); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, ROLE_PREFIX, strlen(ROLE_PREFIX))) { buf += strlen(ROLE_PREFIX); token = strsep(&buf, delim); cmd_data->role = simple_strtoul(token, NULL, 10); if (INVALID_ROLE(cmd_data->role)) { WL_ERR((" invalid role, role = %d \n", cmd_data->role)); ret = -EINVAL; goto fail; } } else if (!strncmp(buf, MASTER_PREF_PREFIX, strlen(MASTER_PREF_PREFIX))) { buf += strlen(MASTER_PREF_PREFIX); token = strsep(&buf, delim); cmd_data->master_pref = simple_strtoul(token, NULL, 10); } else if (!strncmp(buf, PUB_PR_PREFIX, strlen(PUB_PR_PREFIX))) { buf += strlen(PUB_PR_PREFIX); token = strsep(&buf, delim); cmd_data->pub_pr = simple_strtoul(token, NULL, 10); } else if (!strncmp(buf, PUB_INT_PREFIX, strlen(PUB_INT_PREFIX))) { buf += strlen(PUB_INT_PREFIX); token = strsep(&buf, delim); cmd_data->pub_int = simple_strtoul(token, NULL, 10); } else if (!strncmp(buf, DW_LEN_PREFIX, strlen(DW_LEN_PREFIX))) { buf += strlen(DW_LEN_PREFIX); token = strsep(&buf, delim); cmd_data->dw_len = simple_strtoul(token, NULL, 10); } else if (!strncmp(buf, DEBUG_PREFIX, strlen(DEBUG_PREFIX))) { buf += strlen(DEBUG_PREFIX); token = strsep(&buf, delim); cmd_data->debug_flag = simple_strtoul(token, NULL, 10); } else { WL_ERR((" unknown token, token = %s, buf = %s \n", token, buf)); ret = -EINVAL; goto fail; } } fail: return ret; }
int gen_stateless_conf(void) { int ret; FILE *fp; int l_len; // check security char auth[8]; char crypto[16]; char beacon[] = "WPAand11i"; char encryption[] = "TKIPandAESEncryption"; char key[65]; char ssid[65]; char region[5]; int channel = wf_chspec_ctlchan(wf_chspec_aton(nvram_safe_get("wl1_chanspec"))); int bw = atoi(nvram_safe_get("wl1_bw")); uint32_t index = 0; sprintf(ssid, "%s", nvram_safe_get("wl1_ssid")); sprintf(region, "%s", nvram_safe_get("1:ccode")); dbg("[stateless] channel:[%d]\n", channel); dbg("[stateless] bw:[%d]\n", bw); fp = fopen("/tmp/stateless_slave_config", "w"); if(nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 1 && nvram_get_int("wlc_band") == 1){ /* media bridge mode */ fprintf(fp, "wifi0_mode=sta\n"); strncpy(auth, nvram_safe_get("wlc_auth_mode"), sizeof(auth)); strncpy(crypto, nvram_safe_get("wlc_crypto"), sizeof(crypto)); strncpy(key, nvram_safe_get("wlc_wpa_psk"), sizeof(key)); strncpy(ssid, nvram_safe_get("wlc_ssid"), sizeof(ssid)); fprintf(fp, "wifi0_SSID=\"%s\"\n", ssid); logmessage("start_psta", "ssid=%s, auth=%s, crypto=%s, encryption=%s, key=%s\n", ssid, auth, crypto, encryption, key); /* convert security from nvram to qtn */ if(!strcmp(auth, "psk2") && !strcmp(crypto, "aes")){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=11i\n"); fprintf(fp, "wifi0_encryption=AESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "aes") ){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=WPAand11i\n"); fprintf(fp, "wifi0_encryption=AESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "tkip+aes") ){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=WPAand11i\n"); fprintf(fp, "wifi0_encryption=TKIPandAESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else{ logmessage("start_psta", "No security in use\n"); fprintf(fp, "wifi0_auth_mode=NONE\n"); fprintf(fp, "wifi0_beacon=Basic\n"); } /* auto channel for media bridge mode */ channel = 0; }else{ /* not media bridge mode */ fprintf(fp, "wifi0_mode=ap\n"); strncpy(auth, nvram_safe_get("wl1_auth_mode_x"), sizeof(auth)); strncpy(crypto, nvram_safe_get("wl1_crypto"), sizeof(crypto)); strncpy(key, nvram_safe_get("wl1_wpa_psk"), sizeof(key)); strncpy(ssid, nvram_safe_get("wl1_ssid"), sizeof(ssid)); fprintf(fp, "wifi0_SSID=\"%s\"\n", ssid); if(!strcmp(auth, "psk2") && !strcmp(crypto, "aes")){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=11i\n"); fprintf(fp, "wifi0_encryption=AESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "aes") ){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=WPAand11i\n"); fprintf(fp, "wifi0_encryption=AESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "tkip+aes") ){ fprintf(fp, "wifi0_auth_mode=PSKAuthentication\n"); fprintf(fp, "wifi0_beacon=WPAand11i\n"); fprintf(fp, "wifi0_encryption=TKIPandAESEncryption\n"); fprintf(fp, "wifi0_passphrase=%s\n", key); } else{ logmessage("start_ap", "No security in use\n"); fprintf(fp, "wifi0_beacon=Basic\n"); } } for( l_len = 0 ; l_len < strlen(region); l_len++){ region[l_len] = tolower(region[l_len]); } fprintf(fp, "wifi0_region=%s\n", region); nvram_set("wl1_country_code", nvram_safe_get("1:ccode")); fprintf(fp, "wifi0_vht=1\n"); if(bw==1) fprintf(fp, "wifi0_bw=20\n"); else if(bw==2) fprintf(fp, "wifi0_bw=40\n"); else if(bw==3) fprintf(fp, "wifi0_bw=80\n"); else fprintf(fp, "wifi0_bw=80\n"); /* if media bridge mode, always auto channel */ fprintf(fp, "wifi0_channel=%d\n", channel); fprintf(fp, "wifi0_pwr=%d\n", get_tx_power_qtn()); if(nvram_get_int("wl1_itxbf") == 1 || nvram_get_int("wl1_txbf") == 1){ fprintf(fp, "wifi0_bf=1\n"); }else{ fprintf(fp, "wifi0_bf=0\n"); } fprintf(fp, "wifi0_staticip=1\n"); fprintf(fp, "slave_ipaddr=\"192.168.1.111/16\"\n"); fprintf(fp, "server_ipaddr=\"%s\"\n", nvram_safe_get("QTN_RPC_SERVER")); fprintf(fp, "client_ipaddr=\"%s\"\n", nvram_safe_get("QTN_RPC_CLIENT")); fclose(fp); return 1; }