# lnwlan_linux_drv **Repository Path**: lightningsemi/lnwlan-linux-drv ## Basic Information - **Project Name**: lnwlan_linux_drv - **Description**: 亮牛半导体 linux wifi 驱动,基于 nl80211 和 cfg80211 。 - **Primary Language**: C - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-07-14 - **Last Updated**: 2024-09-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 亮牛半导体 linux wifi 驱动 > 驱动位置:`drivers/net/wireless/lightningsemi`。 ## 如何使用 ### SDIO WiFi 模块准备 1. 烧录 `dev_bin/flashimage-f9ba8626.bin` 2. 如需要日志串口,请将 USB 转串口模块的 RX 脚接线到芯片的 B9 tx 引脚 日志的波特率 2000000 。 ### SDIO Linux 端准备 1. 使用 git 克隆到 `drivers/net/wireless` 目录,并重命名为 lightningsemi `git clone https://gitee.com/lightningsemi/lnwlan-linux-drv.git drivers/net/wireless/lightningsemi` 2. makefile 修改 打开 Linux 源码下的 `drivers/net/wireless/Makefile` 文件,在文件最后,增加 `obj-$(CONFIG_LN_WIRELESS) += lightningsemi/` 。 3. Kconfig 修改 打开 Linux 源码下的 `drivers/net/wireless/Kconfig` 文件,在文件 `endif` 之前,增加 `source "drivers/net/wireless/lightningsemi/Kconfig"` 。 4. menuconfig 使能 lightningsemi wifi 驱动 ![menuconfig 配置](./docs/lnwifi-menuconfig.png) 5. 打开 Linux 端 WiFi 相关配置(包括 nl80211、sdio) 6. 编译 编译 modules: `make modules -j8` 全编译: `make all -j8` 7. 找打编译后的 `ln882x.ko` 文件 文件位置 `drivers/net/wireless/lightningsemi/ln882x/ln882x.ko` 。 8. 把 `ln882x.ko` 文件推送到 Linux 开发板的 rootfs `lib/modules//` 9. 加载模块 命令行运行命令: ``` # depmod # modprobe ln882x.ko ``` 10. 网卡 up ``` # ifconfig wlan0 up ``` 11. 联网 创建 wpa_conn 文件,内容如下: ``` #!/bin/sh wpa_supplicant -Dnl80211 -c wpa_supplicant.conf -i wlan0 & ``` 创建 wpa_supplicant.conf 文件,内容如下: ``` country=CN ctrl_interface=/var/run/wpa_supplicant update_config=1 network={ ssid="DeviceTestOnly" psk="devicetest123" } ``` 注意,如果是未加密的路由器,请使用如下配置: ``` country=CN ctrl_interface=/var/run/wpa_supplicant update_config=1 network={ ssid="DeviceTestOnlyOpen" key_mgmt=NONE } ``` 联网: 使用命令 `./wpa_conn` 连接 wpa_supplicant.conf 文件指定的 SSID 的路由器。 成功连上路由器后会有日志(根据日志级别的配置情况): ``` wlan0: CTRL-EVENT-CONNECTED - Connection to c0:a5:dd:84:6f:a8 completed ``` 12. 获取 ip 地址 使用命令 `udhcpc -i wlan0` 获取 ip 地址。 ## 注意事项 1. LN882x 系列 WiFi 芯片 SDIO 仅支持 high speed 模式,且 card clk 最大支持 25Mhz 因此,请修改 Linux 端的 SDIO 配置中的 card clk 为 25Mhz。 通常 high speed 模式下默认是 50MHz,但是 LN882x 系列卡无法支持。 2. 请务必确保 SDIO WiFi 模块先上电(初始化 SDIO slave) ## QA 1. 无法成功加载 ln882x.ko 模块 - 请使用逻辑分析仪观察 SDIO CLK 和 CMD 引脚是否有波形出来。 - 确保 CD 引脚被 Linux 端检测到(CD 引脚默认是高电平,插上 WiFi 模块后会变成低电平) - 检查 SDIO 引脚上的串接电阻和上拉电阻情况,跟芯片原厂确认 ## License > Lightningsemi’s linux wifi driver. > > Copyright (C) 2017 - 2021 [LightningSemi Technology Co](http://www.lightningsemi.com/). All rights reserved. > > This program is free software: you can redistribute it and/or modify > it under the terms of the GNU General Public License as published by > the Free Software Foundation, either version 3 of the License, or > (at your option) any later version. > > This program is distributed in the hope that it will be useful, > but WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > GNU General Public License for more details. > > You should have received a copy of the GNU General Public License > along with this program. If not, see . > > Contact Information: > marketing@lightningsemi.com ### 源代码文件头 license 信息 ``` /** * @file xxx.c * @author LightningSemi WLAN Team * * Copyright (C) 2017-2021 LightningSemi Technology Co., Ltd. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Contact Information: * marketing@lightningsemi.com * * Change Logs: * Date Author Notes * 2021-02-22 MurphyZhao the first version */ ``` ## WiFi 驱动说明 ### 使用动态 mac 地址 请使能宏定义 LNWLAN_MACADDR_DYNAMIC ,并且屏蔽 LNWLAN_DEFAULT_STA_MAC_ADDR 宏定义。 如果使能了 LNWLAN_MACADDR_DYNAMIC 宏定义,会使用函数 lnwlan_get_mac_address_from_nvram 从 nvram 里查找上次保存的随机 mac 地址, 如果在 nvram 里没有找到这个地址,那么就调用函数 random_ether_addr 生成一个随机地址,然后存入 nvram 里。 ### 使用 WiFi 从机里的 mac 地址 请使能宏定义 LNWLAN_USE_WIFI_DEV_MAC 。 尚未经过验证。 还不清楚什么时间读取 WiFi 设备里的 mac 地址,并配置到 linux netif 里? 动态 mac 地址是通过调用 lnwlan_add_if 函数传递的 mac 地址。 ### Linux 设置 mac 地址到 WiFi 芯片 调用函数 lnwlan_set_mac_address 。 ## TODOs