📄 prism2mgmt.c
字号:
* wlandev wlan device structure* msgp ptr to msg buffer** Returns: * 0 success and done* <0 success, but we're waiting for something to finish.* >0 an error occurred while handling the message.* Side effects:** Call context:* process thread (usually)* interrupt----------------------------------------------------------------*/int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp){ int result = 0; p80211msg_dot11req_scan_results_t *req; hfa384x_t *hw = wlandev->priv; hfa384x_HScanResultSub_t *item = NULL; int count; DBFENTER; req = (p80211msg_dot11req_scan_results_t *) msgp; req->resultcode.status = P80211ENUM_msgitem_status_data_ok; if (hw->ap) { result = 1; req->resultcode.data = P80211ENUM_resultcode_not_supported; goto exit; } if (! hw->scanresults) { WLAN_LOG_ERROR("dot11req_scan_results can only be used after a successful dot11req_scan.\n"); result = 2; req->resultcode.data = P80211ENUM_resultcode_invalid_parameters; goto exit; } count = (hw->scanresults->framelen - 3) / 32; if (count > 32) count = 32; if (req->bssindex.data >= count) { WLAN_LOG_DEBUG(0, "requested index (%d) out of range (%d)\n", req->bssindex.data, count); result = 2; req->resultcode.data = P80211ENUM_resultcode_invalid_parameters; goto exit; } item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]); /* signal and noise */ req->signal.status = P80211ENUM_msgitem_status_data_ok; req->noise.status = P80211ENUM_msgitem_status_data_ok; req->signal.data = hfa384x2host_16(item->sl); req->noise.data = hfa384x2host_16(item->anl); /* BSSID */ req->bssid.status = P80211ENUM_msgitem_status_data_ok; req->bssid.data.len = WLAN_BSSID_LEN; memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN); /* SSID */ req->ssid.status = P80211ENUM_msgitem_status_data_ok; req->ssid.data.len = hfa384x2host_16(item->ssid.len); memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len); /* supported rates */ for (count = 0; count < 10 ; count++) if (item->supprates[count] == 0) break;#define REQBASICRATE(N) \ if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \ req->basicrate ## N .data = item->supprates[(N)-1]; \ req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \ } REQBASICRATE(1); REQBASICRATE(2); REQBASICRATE(3); REQBASICRATE(4); REQBASICRATE(5); REQBASICRATE(6); REQBASICRATE(7); REQBASICRATE(8);#define REQSUPPRATE(N) \ if (count >= N) { \ req->supprate ## N .data = item->supprates[(N)-1]; \ req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \ } REQSUPPRATE(1); REQSUPPRATE(2); REQSUPPRATE(3); REQSUPPRATE(4); REQSUPPRATE(5); REQSUPPRATE(6); REQSUPPRATE(7); REQSUPPRATE(8); /* beacon period */ req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok; req->beaconperiod.data = hfa384x2host_16(item->bcnint); /* timestamps */ req->timestamp.status = P80211ENUM_msgitem_status_data_ok; req->timestamp.data = jiffies; req->localtime.status = P80211ENUM_msgitem_status_data_ok; req->localtime.data = jiffies; /* atim window */ req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok; req->ibssatimwindow.data = hfa384x2host_16(item->atim); /* Channel */ req->dschannel.status = P80211ENUM_msgitem_status_data_ok; req->dschannel.data = hfa384x2host_16(item->chid); /* capinfo bits */ count = hfa384x2host_16(item->capinfo); /* privacy flag */ req->privacy.status = P80211ENUM_msgitem_status_data_ok; req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count); /* cfpollable */ req->cfpollable.status = P80211ENUM_msgitem_status_data_ok; req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count); /* cfpollreq */ req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok; req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count); /* bsstype */ req->bsstype.status = P80211ENUM_msgitem_status_data_ok; req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ? P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent; // item->proberesp_rate/* req->fhdwelltime req->fhhopset req->fhhoppattern req->fhhopindex req->cfpdurremaining*/ result = 0; req->resultcode.data = P80211ENUM_resultcode_success; exit: DBFEXIT; return result;}/*----------------------------------------------------------------* prism2mgmt_join** Join a BSS whose BSS description was previously obtained with* a scan.** Arguments:* wlandev wlan device structure* msgp ptr to msg buffer** Returns: * 0 success and done* <0 success, but we're waiting for something to finish.* >0 an error occurred while handling the message.* Side effects:** Call context:* process thread (usually)* interrupt----------------------------------------------------------------*/int prism2mgmt_join(wlandevice_t *wlandev, void *msgp){ int result = 0; hfa384x_t *hw = wlandev->priv; p80211msg_dot11req_join_t *msg = msgp; DBFENTER; if (!hw->ap) { /*** STATION ***/ /* TODO: Implement after scan */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_not_supported; } else { /*** ACCESS POINT ***/ /* Never supported by APs */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_not_supported; } DBFEXIT; return result;}/*----------------------------------------------------------------* prism2mgmt_p2_join** Join a specific BSS** Arguments:* wlandev wlan device structure* msgp ptr to msg buffer** Returns: * 0 success and done* <0 success, but we're waiting for something to finish.* >0 an error occurred while handling the message.* Side effects:** Call context:* process thread (usually)* interrupt----------------------------------------------------------------*/int prism2mgmt_p2_join(wlandevice_t *wlandev, void *msgp){ int result = 0; hfa384x_t *hw = wlandev->priv; p80211msg_p2req_join_t *msg = msgp; UINT16 reg; p80211pstrd_t *pstr; UINT8 bytebuf[256]; hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t*)bytebuf; hfa384x_JoinRequest_data_t joinreq; DBFENTER; if (!hw->ap) { wlandev->macmode = WLAN_MACMODE_NONE; /*** STATION ***/ /* Set the PortType */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_success; /* ess port */ result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 1); if ( result ) { WLAN_LOG_ERROR("Failed to set Port Type\n"); goto failed; } /* Set the auth type */ if ( msg->authtype.data == P80211ENUM_authalg_sharedkey ) { reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY; } else { reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM; } result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg); if ( result ) { WLAN_LOG_ERROR("Failed to set Authentication\n"); goto failed; } /* Turn off all roaming */ hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE, 3); if ( result ) { WLAN_LOG_ERROR("Failed to Turn off Roaming\n"); goto failed; } /* Basic rates */ reg = 0; if ( msg->basicrate1.status == P80211ENUM_msgitem_status_data_ok ) { reg = p80211rate_to_p2bit(msg->basicrate1.data); } if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate2.data); } if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate3.data); } if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate4.data); } if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate5.data); } if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate6.data); } if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate7.data); } if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->basicrate8.data); } if( reg == 0) reg = 0x03; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, reg); if ( result ) { WLAN_LOG_ERROR("Failed to set basicrates=%d.\n", reg); goto failed; } /* Operational rates (supprates and txratecontrol) */ reg = 0; if ( msg->operationalrate1.status == P80211ENUM_msgitem_status_data_ok ) { reg = p80211rate_to_p2bit(msg->operationalrate1.data); } if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate2.data); } if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate3.data); } if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate4.data); } if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate5.data); } if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate6.data); } if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate7.data); } if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) { reg |= p80211rate_to_p2bit(msg->operationalrate8.data); } if( reg == 0) reg = 0x0f; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, reg); if ( result ) { WLAN_LOG_ERROR("Failed to set supprates=%d.\n", reg); goto failed; } result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, reg); if ( result ) { WLAN_LOG_ERROR("Failed to set txrates=%d.\n", reg); goto failed; } /* Set the ssid */ memset(bytebuf, 0, 256); pstr = (p80211pstrd_t*)&(msg->ssid.data); prism2mgmt_pstr2bytestr(p2bytestr, pstr); result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFDESIREDSSID, bytebuf, HFA384x_RID_CNFDESIREDSSID_LEN); if ( result ) { WLAN_LOG_ERROR("Failed to set SSID\n"); goto failed; } /* Enable the Port */ result = hfa384x_cmd_enable(hw, 0); if ( result ) { WLAN_LOG_ERROR("Enable macport failed, result=%d.\n", result); goto failed; } /* Fill in the join request */ joinreq.channel = msg->channel.data; memcpy( joinreq.bssid, ((unsigned char *) &msg->bssid.data) + 1, WLAN_BSSID_LEN); hw->joinreq = joinreq; hw->join_ap = 1; /* Send the join request */ result = hfa384x_drvr_setconfig( hw, HFA384x_RID_JOINREQUEST, &joinreq, HFA384x_RID_JOINREQUEST_LEN); if(result != 0) { WLAN_LOG_ERROR("Join request failed, result=%d.\n", result); goto failed; } } else { /*** ACCESS POINT ***/ /* Never supported by APs */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_not_supported; } goto done;failed: WLAN_LOG_DEBUG(1, "Failed to set a config option, result=%d\n", result); msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;done: result = 0; DBFEXIT; return result;}/*----------------------------------------------------------------* prism2mgmt_authenticate** Station should be begin an authentication exchange.** Arguments:* wlandev wlan device structure* msgp ptr to msg buffer** Returns: * 0 success and done* <0 success, but we're waiting for something to finish.* >0 an error occurred while handling the message.* Side effects:** Call context:* process thread (usually)* interrupt----------------------------------------------------------------*/int prism2mgmt_authenticate(wlandevice_t *wlandev, void *msgp){ int result = 0; hfa384x_t *hw = wlandev->priv; p80211msg_dot11req_authenticate_t *msg = msgp; DBFENTER; if (!hw->ap) { /*** STATION ***/ /* TODO: Decide how we're going to handle this one w/ Prism2 */ /* It could be entertaining since Prism2 doesn't have */ /* an explicit way to control this */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_not_supported; } else { /*** ACCESS POINT ***/ /* Never supported by APs */ msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; msg->resultcode.data = P80211ENUM_resultcode_not_supported; } DBFEXIT; return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -