mtk_wlan_driver_code_analyse

本文详细分析了MTK WLAN驱动的初始化流程,包括国家码country_ops的重要性,特别是COUNTRY_CODE_FF和COUNTRY_CODE_FE两个特殊代码。还介绍了如何通过procCountryWrite设置国家代码,影响工作频段和TX功率。此外,讲解了从创建wiphy到注册net_device的步骤,以及cfg80211_ops中涉及的各种网络操作,如连接、扫描和加密等。
摘要由CSDN通过智能技术生成

1.    kernel_modules/connectivity/wlan/gen4m/os/linux/gl_init.c


mtk_wcn_wlan_gen2_init-> initWlan();


initWlan(); ---------------wifi driver start !


#if DBG  //defult closed; you can open it when you want to debug wifi log .


kalInitIOBuffer(); ----SDIO buf  alloc


procInitFs(); ---dbglevel_ops(debug module and debug level)
          --- proc_txdone_ops ("ARP", "DNS", "TCP", "UDP", "EAPOL", "DHCP", "ICMP")
          --- auto_per_ops  (Performance Configure)
          --- country_ops// diff country support diff channel
 
重点关注一下国家码country_ops,此信息跟选择的工作频段 TX power 等有关。


Two Special country code:
COUNTRY_CODE_FF    enable open for all channel for Certification
COUNTRY_CODE_FE    disable open for all channel for Certification
static ssize_t procCountryWrite(struct file *file, const char __user *buffer,size_t count, loff_t *data);
 wlanoidSetCountryCode WLAN_STATUS wlanoidSetCountryCode(IN P_ADAPTER_T prAdapter,
              IN PVOID pvSetBuffer, IN UINT_32 u4SetBufferLen, OUT PUINT_32 pu4SetInfoLen)
 pucCountry = pvSetBuffer; 
 prAdapter->rWifiVar.rConnSettings.u2CountryCodeBakup = prAdapter->rWifiVar.rConnSettings.u2CountryCode;
(set country code complete)


     *  For example: 2.4GHz, 1~13, 20MHz ==> regulation class = 81
     *               2.4GHz, 1~13, SCA   ==> regulation class = 83
     *               2.4GHz, 1~13, SCB   ==> regulation class = 84


Force to re-search
rlmDomainSendCmd(prAdapter, TRUE); 
    1 .rlmDomainSendDomainInfoCmd(prAdapter, fgIsOid);
    2. rlmDomainSendPwrLimitCmd(prAdapter);
    3. rlmDomainSendPassiveScanInfoCmd(prAdapter, fgIsOid);


    rlmDomainSendDomainInfoCmd(prAdapter, fgIsOid);
rlmDomainGetDomainInfo(prAdapter); 
//defined three mothed to get country code:
1. by given table idx 2. by customized  3. by country code


    rlmDomainSendPwrLimitCmd(prAdapter); //TX power limit
WLAN_GET_FIELD_BE16(&g_rRlmPowerLimitDefault[u2DefaultTableIndex].aucCountryCode[0],&prCmd->u2CountryCode); // Corresponding country TX power limit allocation
MAX_TX_POWER                    63
MIN_TX_POWER                    -64


rlmDomainBuildCmdByDefaultTable(prCmd, u2DefaultTableIndex); //default table information
rlmDomainBuildCmdByConfigTable(prAdapter, prCmd); // configuration table information


    rlmDomainSendPassiveScanInfoCmd(prAdapter, fgIsOid); //Set passive scan channel info to chip


createWirelessDevice();
/* <1.1> Create wireless_dev */
    prWdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
/* <1.2> Create wiphy */
prWiphy = wiphy_new(&mtk_wlan_ops, sizeof(GLUE_INFO_T));
/* <1.3> configure wireless_dev & wiphy */
...
/* <1.4> wowlan support */
prWiphy->wowlan = &mtk_wlan_wowlan_support;
    /* <1.5> Use wireless extension to replace IOCTL */
prWiphy->wext = &wext_handler_def;


/* <2> allocate and register net_device */
prNetDev = alloc_netdev_mq(sizeof(P_GLUE_INFO_T), NIC_INF_NAME, NET_NAME_PREDICTABLE,
                   ether_setup, CFG_MAX_TXQ_NUM);
prNetDev->netdev_ops = &wlan_netdev_ops;
/* <2.1> co-relate with wireless_dev bi-directionally */
prNetDev->ieee80211_ptr = prWdev;
    prWdev->netdev = prNetDev;
/* <2.2> co-relate net device & device tree */
SET_NETDEV_DEV(prNetDev, wiphy_dev(prWiphy));
/* <2.3> register net_device */
register_netdev(prWdev->netdev)



createWirelessDevice  -> /* <1.2> Create wiphy */
                    phy = wiphy_new(&mtk_wlan_ops, sizeof(GLUE_INFO_T));  Start 
static struct cfg80211_ops mtk_wlan_ops = {
    .suspend = mtk_cfg80211_suspend,
    .resume    = mtk_cfg80211_resume,
    .change_virtual_intf = mtk_cfg80211_change_iface,
//wlanoidSetInfrastructureMode   1. Infrastructure Client (Non-AP STA) = AP + STA  2. Ad-Hoc IBSS = STA+ STA
    .add_key = mtk_cfg80211_add_key,
    // mtk_cfg80211_add_key -> wlanoidSetAddKey -> _wlanoidSetAddKey (wlan_oid.c) 
    According to the different prNewKey-> u4KeyLength, select the encryption method. 
    /* rKey.u4KeyIndex |= BIT(31);//Enable BIT 31 will make tx use bc key id,should use pairwise key id 0 */
    .get_key = mtk_cfg80211_get_key,
    .del_key = mtk_cfg80211_del_key,
    .set_default_key = mtk_cfg80211_set_default_key,
    .set_default_mgmt_key = mtk_cfg80211_set_default_mgmt_key,
    .get_station = mtk_cfg80211_get_station,  
    //This routine is responsible for getting station information such as RSSI
    /* 1. check BSSID */
    UNEQUAL_MAC_ADDR(arBssid, mac)
    /* 2. fill TX rate */
    wlanoidQueryLinkSpeed
    /* 3. fill RSSI */
    wlanoidQueryRssi   
    Contradictory point:
    rRssi = (PARAM_RSSI) prAdapter->rLinkQuality.cRssi;    /* ranged from (-128 ~ 30) in unit of dBm */
    #define PARAM_WHQL_RSSI_MAX_DBM                 (-10)
#define PARAM_WHQL_RSSI_MIN_DBM                 (-200)
    
    /* 4. Fill Tx OK and Tx Bad */
    wlanoidQueryStatisticsPL
.change_station = mtk_cfg80211_change_station,
    .add_station = mtk_cfg80211_add_station,
    .del_station = mtk_cfg80211_del_station,
    .scan = mtk_cfg80211_scan,
    #define CFG_SCAN_SSID_MAX_NUM                   (4)
#define CFG_SCAN_SSID_MATCH_MAX_NUM             (16)
#if CFG_MULTI_SSID_SCAN
wlanoidSetBssidListScanAdv
wlanoidGetChannelInfo(prAdapter, prScanRequest->puPartialScanReq);// get channel list
aisFsmScanRequestAdv(prAdapter, ucSsidNum, rSsid, pucIe, u4IeLength);
{//遍历赋值ssid,此方法多次使用,请以适当的场景赋值为准
            for (i = 0; i < ucSsidNum; i++) {
                COPY_SSID(prAisFsmInfo->arScanSSID[i].aucSsid,
                      prAisFsmInfo->arScanSSID[i].u4SsidLen,
                      prSsid[i].aucSsid, prSsid[i].u4SsidLen);
}


/* start online scan */
wlanClearScanningResult(prAdapter);
aisFsmSteps(prAdapter, AIS_STATE_ONLINE_SCAN);
{
case AIS_STATE_ONLINE_SCAN:
1、//ssid 赋值(各种扫描方式宏控辅助)
COPY_SSID(prAisFsmInfo->rRoamingSSID.aucSsid,prAisFsmInfo->rRoamingSSID.u4SsidLen,prConnSettings->aucSSID,prConnSettings->ucSSIDLen); 
2、//channel 获取
}


#else
wlanoidSetBssidListScanExt
// The difference between the two cases is: last case did not achieve aisFsmScanRequestAdv(fun :LIST_SCAN) function.
#endif
    .connect = mtk_cfg80211_connect,
1.    wlanoidSetInfrastructureMode 
    {
        /* Verify the new infrastructure mode. */基础架构BSS 网络
    if (eOpMode >= NET_TYPE_NUM) {
        DBGLOG(OID, TRACE, "Invalid mode value %d\n", eOpMode);
        return WLAN_STATUS_INVALID_DATA;
    }


    /* check if possible to switch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值