int svrQueryNoise(char* ifname, P_GWS_KPI pKpi, int nId) { int region = 0; short nChannel = iw_getcurrchan(pKpi, nId); RW_KPI_VAR(nId,region,pKpi->m_radio.m_nRegion); if (MIN_CHANNEL(region) <= nChannel && nChannel <= MAX_CHANNEL(region)) { return iw_noise(ifname, nChannel, pKpi, nId); } return MIN_CHANNEL_NOISE; }
short svrSetChannel(SerialCom* comm,int region,short channel,int *nTimer) { char command[64]; if (MIN_CHANNEL(region) <= channel && channel <= MAX_CHANNEL(region)) { EnableTimer(*nTimer,PERIOD_SWITCH * MSEC_TICKS); //500 ms to ensure the pll done memset (command, 0x00, 64); sprintf(command, "setchan %d\n", channel); ScSend(comm, command, strlen(command)); return channel; } else return MIN_CHANNEL(region); }
void iw_setchannel(int nChannel, P_GWS_KPI pKpi, int nId) { int region = 0; short chan = nChannel; RW_KPI_VAR(nId,region,pKpi->m_radio.m_nRegion); if (MIN_CHANNEL(region) <= chan && chan <= MAX_CHANNEL(region)) { RW_KPI_VAR(nId,pKpi->m_currchannel,chan); } else if (-1 == chan) { RW_KPI_VAR(nId,pKpi->m_currchannel,chan); } else { RW_KPI_VAR(nId,pKpi->m_currchannel,MIN_CHANNEL(region)); } }
/* * Get Frequency given a Channel number */ guint ieee80211_chan_to_mhz(gint chan, gboolean is_bg) { guint i; for (i = 0; i < NUM_FREQ_CVT; i++) { if (is_bg == freq_cvt[i].is_bg && chan >= freq_cvt[i].cmin && chan <= MAX_CHANNEL(freq_cvt[i])) { return ((chan - freq_cvt[i].cmin) * FREQ_STEP) + freq_cvt[i].fmin; } } return 0; }
void sp2lcd_intl(const uint _debug,P_GWS_KPI pKpiLcd,int nKpiLcdId,char report,int local_sta) { static char nf_report_counter[MAX_CH_NUM]; char _buf[SP_BUF_MAX_LEN]; memset(_buf, 0, sizeof (_buf)); if (pKpiLcd) { int region = 0; RW_KPI_VAR(nKpiLcdId,region,pKpiLcd->m_radio.m_nRegion); if (MIN_CHANNEL(region) <= lcd_cache.m_nScanStartChan && lcd_cache.m_nScanStartChan <= MAX_CHANNEL(region)) { time_t current_time = time(¤t_time); //scanning demanded by LCD time_t time_escaped = current_time - lcd_cache.m_timer; if (time_escaped > 180) { //time out lcd_cache.m_nScanStartChan = 0; lcd_cache.m_timer = 0; } else if (time_escaped < 1) { //first channel not done yet,do nothing memset( nf_report_counter,0x00,MAX_CH_NUM); } else if (svrIsScanning()) { short ch = iw_getcurrchan(pKpiLcd,nKpiLcdId,nKpiLcdId) - 1; if (ch < MIN_CHANNEL(region)) ch = MAX_CHANNEL(region); if (MIN_CHANNEL(region) <= ch && ch <= MAX_CHANNEL(region)) { int sn = ch - lcd_cache.m_nScanStartChan; if (sn < 0) sn += NUM_CHANNEL(region); if (nf_report_counter[sn] < 3) { nf_report_counter[sn] ++; _KPI_HOLD_ BUILD_NF_ECHO(_buf,ch,pKpiLcd->m_noise_floor[ch-MIN_CHANNEL(region)].m_noise_avg,sn,0); _KPI_FREE_ LCD_DEBUG(_debug,"channel scan = %d [%d]\n",ch,lcd_cache.m_nScanStartChan); } else return; } else LCD_DEBUG(_debug,"channel scan = %d *\n",ch); } else { //scan has done,(chp.m_nOriginChannel == chp.m_nCurrentChannel) short ch = lcd_cache.m_nScanStartChan; _KPI_HOLD_ BUILD_NF_ECHO(_buf,ch,pKpiLcd->m_noise_floor[ch-MIN_CHANNEL(region)].m_noise_avg,NUM_CHANNEL(region),1); _KPI_FREE_ LCD_DEBUG(_debug,"channel scan = %d\n",lcd_cache.m_nScanStartChan); lcd_cache.m_nScanStartChan = 3; //act as counter for sending scan result 3 times lcd_cache.m_timer = 0; } } else if (0 < lcd_cache.m_nScanStartChan && lcd_cache.m_nScanStartChan <= 3) { sprintf(_buf, "+wbrch:%s\r\n", gws_get_chlist(region)); lcd_cache.m_nScanStartChan --; } else { if (REPORT_STATUS == report) { //common status report int nChannel = MIN_CHANNEL(region),nTxPower = 0,nMode = 2,nSNR = 0; time_t current_time = time(¤t_time); _KPI_HOLD_ if (strstr(pKpiLcd->m_wifi.m_sMode,"Master")) nMode = 2; //AP else if(strstr(pKpiLcd->m_wifi.m_sMode,"Client")) nMode = 1; //STA else nMode = 0; //MESH NODE nChannel = pKpiLcd->m_radio.m_nChanNo; nTxPower = pKpiLcd->m_radio.m_bTX ? pKpiLcd->m_radio.m_nCurTxPwr : 0; nSNR = gws_cal_snr(pKpiLcd->m_wifi.m_nSignal, pKpiLcd->m_wifi.m_nNoise); _KPI_FREE_ if (current_time - lcd_cache.m_timer < 10) { if (lcd_cache.m_nMode >= 0) nMode = lcd_cache.m_nMode; if (lcd_cache.m_nChannel >= 0) nChannel = lcd_cache.m_nChannel; if (lcd_cache.m_nTxPower >= 0) nTxPower = lcd_cache.m_nTxPower; } else { lcd_cache.m_nMode = nMode; lcd_cache.m_nChannel = nChannel; lcd_cache.m_nTxPower = nTxPower; } sprintf(_buf, "\r\n+wbsts:%d,%d,%d,%d\r\n", nChannel,nSNR, nTxPower, nMode); LCD_DEBUG(_debug,"\t[%02d:%02d:%02d] <+wbsts:%d,%d,%d,%d>\n", (current_time % 86400) / 3600, ((current_time % 86400) % 3600) / 60, ((current_time % 86400) % 3600) % 60, nChannel,nSNR, nTxPower, nMode); } else if (REPORT_MULTI_SNR == report) { //multi SNR report _KPI_HOLD_ int snrs[5] = {0,0,0,0,0}; //max 5 mesh points int i,nAssoc = pKpiLcd->m_assoc_list.m_nLine; for (i = 0; i < nAssoc; i ++) { int sta = pKpiLcd->m_assoc_list.m_index[i]; int snr = parse_assoc_list_string(pKpiLcd->m_assoc_list.m_value[i]); if (1 <= sta && sta <= 5) { snrs[sta-1] = snr; } } _KPI_FREE_ if (1 <= local_sta && local_sta <= 5) snrs[local_sta-1] = 99; // if (nAssoc > 0) { { time_t current_time = time(¤t_time); sprintf(_buf, "\r\n+wbsigs:%d,%d,%d,%d,%d\r\n", snrs[0],snrs[1],snrs[2],snrs[3],snrs[4]); LCD_DEBUG(_debug,"\t[%02d:%02d:%02d] <+wbsigs:%d,%d,%d,%d,%d>\n", (current_time % 86400) / 3600, ((current_time % 86400) % 3600) / 60, ((current_time % 86400) % 3600) % 60, snrs[0],snrs[1],snrs[2],snrs[3],snrs[4]); } } else return; //REPORT_NONE
//the max and min noise will not counted int iw_noise(const char* ifname, int nChannel, P_GWS_KPI pKpi, int nId) { //ifname == NULL means reset const struct iwinfo_ops* iw = &nl80211_ops; int region = 0; RW_KPI_VAR(nId,region,pKpi->m_radio.m_nRegion); if (MIN_CHANNEL(region) <= nChannel && nChannel <= MAX_CHANNEL(region)) { static int nSamples; int chan_idx = nChannel-MIN_CHANNEL(region); // 0 based channel index if (ifname) { int curr = 0; iw->noise(ifname, &curr); RW_KPI_VAR(nId,pKpi->m_wifi.m_nNoise,curr); #if (MAX_AVG == 1) do { int curr_nf = curr; char max = 0, min = 0; RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_cur,curr); RW_KPI_VAR(nId,max,pKpi->m_noise_floor[chan_idx].m_noise_max); RW_KPI_VAR(nId,min,pKpi->m_noise_floor[chan_idx].m_noise_min); if (0 == max) { //no max value at first time RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_max,curr_nf); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_avg,curr_nf); } else if (0 == min) { //no min value yet NF_CHECK_MAX(max,curr_nf); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_max,max); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_avg,curr_nf); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_min,curr_nf); // } else if (max > MAX_NOISE_FLOOR) { //interference exsit // if (curr_nf > MAX_NOISE_FLOOR) { //only noise above max NF will counted // NF_COUNT_AVG(max,curr_nf,min,nSamples); // } } else { //already have a max value AND a min value NF_COUNT_AVG(max,curr_nf,min,nSamples); } } while (0); return curr; //give the max value and return #elif (MAX_AVG == 2) do { //ignore the max value and the min value, get the avg value of the rest int curr_nf = curr; RW_KPI_VAR(nId,avg,pKpi->m_noise_list[chan_idx]); //pick up average noise if (0 == static_max_min_nf[chan_idx].max) { //no max value first time static_max_min_nf[chan_idx].max = curr; RW_KPI_VAR(nId,pKpi->m_noise_list[chan_idx],curr_nf); return curr_nf; //give the max value and return } else { //already have a max value, update it if needed and keep the smaller one in curr NF_CHECK_MAX(static_max_min_nf[chan_idx].max,curr); if (0 == static_max_min_nf[chan_idx].min) { //no min value yet static_max_min_nf[chan_idx].min = curr; RW_KPI_VAR(nId,pKpi->m_noise_list[chan_idx],curr_nf); return curr_nf; //give the min value and return } else { //already have a max value AND a min value nSamples ++; //update min value if needed and keep the bigger one in curr NF_CHECK_MIN(static_max_min_nf[chan_idx].min,curr); avg = AVG_NOISE(avg,curr,nSamples); //now curr is between max & min, add it to avg //save the avg value without the max and the min counted RW_KPI_VAR(nId,pKpi->m_noise_list[chan_idx],(int)avg); return curr_nf; //return current nf } } } while (0); #else do { curr = MAX_NOISE(pKpi->m_noise_list[chan_idx],curr); RW_KPI_VAR(nId,pKpi->m_noise_list[chan_idx],curr); return curr; } while (0); #endif } else { nSamples = 0; RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_max,0); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_min,0); RW_KPI_VAR(nId,pKpi->m_noise_floor[chan_idx].m_noise_avg,MIN_CHANNEL_NOISE); return MIN_CHANNEL_NOISE; } } return 0; }
int svrCmdHandler(SerialCom* comm,GWS_MESSAGE* gws_msg,CommandHandlerPara* para) { char command[64]; char parameter[32]; int* nTimer = &(para->m_nCommBusy); int region = 0; int nId = para->m_nIdentifier; P_GWS_KPI pKpi = para->m_pKpi; RW_KPI_VAR(nId,region,pKpi->m_radio.m_nRegion); strcpy(parameter, gws_msg->m_command.m_sPara); switch (gws_msg->m_command.m_nReq) { case SCAN_CHAN: case SCAN_FIXED_CHAN: if (MIN_CHANNEL(region) <= para->m_nOriginChannel && para->m_nOriginChannel <= MAX_CHANNEL(region)) { COM_LOCK(1000 * MSEC_TICKS); //occupy serial port for 500 ms RW_KPI_VAR(nId,latest_rxcal,pKpi->m_radio.m_bRXCal); RW_KPI_VAR(nId,latest_rxgain,pKpi->m_radio.m_nRXGain); PRE_SCAN_COMMAND(comm,"setrxcal 0"); PRE_SCAN_COMMAND(comm,"setrxgain 0"); para->m_nCurrentChannel = para->m_nOriginChannel; CHANNEL_SCAN_ON_OFF(para->m_uChanScan,gws_msg->m_command.m_nReq == SCAN_FIXED_CHAN ? SCANNING_FIXED_INIT : SCANNING_ALL_INIT); gws_msg->m_nType = 0; } else { svrSetErrorNo(GWS_ERROR_INVALIDATE_CHANNEL); } break; case STOP_CHAN: if (para->m_uChanScan == SCANNING_FIXED_READ) { CHANNEL_SCAN_ON_OFF(para->m_uChanScan, SCANNING_FIXED_DONE); } else { CHANNEL_SCAN_ON_OFF(para->m_uChanScan, SCANNING_DONE); APP_SCAN_COMMAND(comm,static_chp.m_nOriginChannel); } gws_msg->m_nType = 0; break; case SET_TXON: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "tx%s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_RXON: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "rx%s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_TXCAL: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "settxcal %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } case SET_RXCAL: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "setrxcal %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_REGION: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "setregion %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_CHAN: if (*nTimer <= 0) { int new_channel = para->m_nOriginChannel; COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms CHANNEL_SCAN_ON_OFF(para->m_uChanScan,false); if (IsNumber(parameter)) { new_channel = atoi(parameter); } else if (parameter[0] == 'x') { new_channel --; if (new_channel < MIN_CHANNEL(region)) new_channel = MAX_CHANNEL(region); } else if (parameter[0] == 'v') { new_channel ++; if (new_channel > MAX_CHANNEL(region)) new_channel = MIN_CHANNEL(region); } para->m_nCurrentChannel = new_channel; para->m_nOriginChannel = svrSetChannel(comm, region,para->m_nCurrentChannel,&timer_chan_switch); gws_msg->m_nType = 0; } break; case SET_TXPWR: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "settxpwr %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_GAIN: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "setrxgain %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_MODE: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "config_%s", parameter); system(command); usleep(1000000); system("reboot"); gws_msg->m_nType = 0; } break; case SET_TXATT: if (*nTimer <= 0) { COM_LOCK(500 * MSEC_TICKS); //occupy serial port for 500 ms sprintf(command, "settxatten %s\n", parameter); ScSend(comm, command, strlen(command)); gws_msg->m_nType = 0; } break; case SET_BANDWIDTH: set_wifi_bandwidth(parameter); gws_msg->m_nType = 0; break; case WIFI_TXPW: PipeShellCommand( para->m_shell, "iw", "dev", para->m_ifName, "set", "txpower", "fixed", gws_msg->m_command.m_sPara, NULL); gws_msg->m_nType = 0; break; case 'Q': case 'q': CHANNEL_SCAN_ON_OFF(para->m_uChanScan,false); SetTimerOut(*nTimer); gws_msg->m_nType = 0; break; case SHUTDOWN: #ifdef _GWS_DEBUG ShowStatusBar("Shutdown Server."); #endif gws_msg->m_nType = 0; return 0; default: gws_msg->m_nType = 0; } return 1; }