Skip navigation
Home > All Places > Wi-Fi/Bluetooth for Linux and Android > Blog > Authors VinayakS_26
VinayakS_26

FMAC Debugging

Posted by VinayakS_26 Moderator Feb 4, 2020

Introduction

 

The following blog post discusses on the procedure of enabling Debug flag in FMAC driver.

 

Steps

 

1. If you are building against the running kernel , then enable the following flags in the .config file while preparing the brcmfmac module.

 

CPTCFG_BRCM_TRACING=y

CPTCFG_BRCMDBG=y

CPTCFG_BRCMFMAC_PROTO_BCDC=y

CPTCFG_BRCMFMAC_PROTO_MSGBUF=y

 

else if you are building with the kernel source, then modify the .config of the kernel source with the following

 

CONFIG_BRCMDBG=y

CONFIG_DEBUG_FS=y

 

2. Compile the brcmfmac driver source  for the kernel for which it is being used.

 

#apply the required patch from the latest release.

#patch -p1<diff_fix_linux-v4.12_kernel_for_brcmfmac_build.patch

$make -C <path_to_kernel_src> M=<fmac_source_dir>

To build against the running kernel use:

$ make -C /lib/modules/`uname -r`/build M=$PWD

 

3. Enable brcmfmac debug log

 

$echo 8 > /proc/sys/kernel/printk

 

4. Insert the driver module with the required message level as module parameter.

list out the parameters accepted by the brcmfmac driver that is inserted in the kernel.

 

$ls /sys/module/brcmfmac/parameters/

$insmod brcmfmac.ko debug=${BRCMF_Message_Level}

 

Following are a list of Message levels defined in the debug.h(/v4.14.52-backports/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h)

 

#define BRCMF_TRACE_VAL 0x00000002

#define BRCMF_INFO_VAL 0x00000004

#define BRCMF_DATA_VAL 0x00000008

#define BRCMF_CTL_VAL 0x00000010

#define BRCMF_TIMER_VAL 0x00000020

#define BRCMF_HDRS_VAL 0x00000040

#define BRCMF_BYTES_VAL 0x00000080

#define BRCMF_INTR_VAL 0x00000100

#define BRCMF_GLOM_VAL 0x00000200

#define BRCMF_EVENT_VAL 0x00000400

#define BRCMF_BTA_VAL 0x00000800

#define BRCMF_FIL_VAL 0x00001000

#define BRCMF_USB_VAL 0x00002000

#define BRCMF_SCAN_VAL 0x00004000

#define BRCMF_CONN_VAL 0x00008000

#define BRCMF_BCDC_VAL 0x00010000

#define BRCMF_SDIO_VAL 0x00020000

#define BRCMF_MSGBUF_VAL 0x00040000

#define BRCMF_PCIE_VAL 0x00080000

#define BRCMF_FWCON_VAL 0x00100000

#define BRCMF_ULP_VAL 0x00200000

 

eg: To enable wifi fw console log

$ insmod brcmfmac.ko debug=0x00100006 (TRACE, INFO and WIFI_FW_LOG)

eg: To enable Trace

$ insmod brcmfmac.ko debug=0x6 (TRACE and INFO )

 

For further details on the functions associatied with fmac debug, please look into the source code  @

/v4.14.52-backports/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c

VinayakS_26

Concurrent AP and STA

Posted by VinayakS_26 Moderator Sep 30, 2019

Introduction

 

This blog is to demonstrate the setup of Concurrent AP and STA in a linux host(i.MX6 was used for this purpose).

Pre-requisites

 

The host should have the following utilities/daemons running:

1. iw (en:users:documentation:iw [Linux Wireless] )

2. wpa_supplicant and wpa_cli (check out this link for more details:Supplicant in Linux )

3. hostapd ( HostApd setup in Linux  )

 

The wpa_supplicant is used to setup the STA and hostapd is used for setting up the AP.

 

Procedure

 

Steps/ Description
Command /FormatExample /Outputs

To configure the STA:

Configure the wpa_supplicant daemon with the credentials/details of the AP to which your  STA has to connect. For this modify the wpa_suplicant.conf config file.

>>>vi  /etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=0

update_config=1

 

network={

ssid=<YourSSID>  #ssid of your AP to which the device has to connect.

psk=<YourPassphrase>  #Password

  }

 

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=0

update_config=1

 

network={

ssid="yyyyyyyy" #ssid of your AP to which the device has to connect.

psk="xxxxxxxx">  #Password

  }

To configure the AP:

Configure the hostapd daemon with credential/detail of the AP that you want to setup.

>>> vi /etc/hostapd.conf

interface=wlan1

channel=11 

ssid=<Router-Name>

wpa=1

wpa_passphrase=<Passphrase>

 

#above are the major changes to made in the hostapd.conf

#following is a sample hostapd.conf

interface=wlan0

driver=nl80211

ssid=test_ssid

hw_mode=g

channel=1

macaddr_acl=0

auth_algs=1

wpa=2

wpa_key_mgmt=WPA-PSK

wpa_passphrase=test_ssid

rsn_pairwise=CCMP

wpa_pairwise=CCMP

ctrl_interface=/tmp/hostapd

Kill the wpa_supplicant daemon that is already runnnig

>>>grep -aux | grep wpa_supplicant

>>>killall wpa_supplicant

3092  1.0  0.0   1872   364 pts/2    S+   07:49   0:00 grep wpa_supplicant
Remove the existing interface of supplicant>>>rm -rf /var/run/wpa_supplicant/wlan0
Add a virtual interface to setup the AP>>>iw dev wlan0 interface add wlan1 type __ap
Setup the IP address of the AP>>>ifconfig wlan0 192.168.1.3

#Sample output

IPv6: ADDRCONF(NETDEV_UP): wlan1: link is not ready

Start the wpa_supplicant with the nl80211 driver>>>wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B &

#Sample output

root@imx6ulevk:/usr/sbin# Successfully initialized wpa_supplicant

rfkill: Cannot open RFKILL control device

rfkill: Cannot get wiphy information

[1]+  Done                 

root@imx6ulevk:/usr/sbin# IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Enable network and check the status of the connection

>>>wpa_cli -p /var/run/wpa_supplicant -i wlan0 enable_network 0

>>>wpa_cli -p /var/run/wpa_supplicant -i wlan0 status

bssid=f0:5c:19:8a:95:63

freq=2462

ssid=CY-IOT-HOTSPOT

id=0

mode=station

pairwise_cipher=CCMP

group_cipher=CCMP

key_mgmt=WPA2-PSK

wpa_state=COMPLETED

p2p_device_address=62:f1:89:3e:ed:f9

address=xx:xx:xx:xx:xx:xx

uuid=xxxxxxxxxxxxx

Start dhcp client to leased out an IP from your dhcp server. If your AP/router supports static, you could setup a static IP as well using ifconfig.>>>udhcpc -i wlan0 up

#Sample  output

root@imx6ulevk:/usr/sbin# udhcpc -i wlan0 up

udhcpc (v1.24.1) started

Sending discover...

Sending select for 192.168.1.107...

Lease of 192.168.1.107 obtained, lease time 86400

/etc/udhcpc.d/50default: Adding DNS 192.168.1.1

Setup the host AP by calling the hostapd daemon.>>>./hostapd /etc/hostapd.conf -B &

#Sample  output

wlan1: interface state UNINITIALIZED->ENABLED

wlan1: AP-ENABLED
VinayakS_26

Running  BlueZ on CY Part

Posted by VinayakS_26 Moderator Jun 30, 2019

Introduction

 

The blog is to run BlueZ stack on a linux  host machine to initialize Cypress Bluetooth Controller, which is connected to Ubuntu machine through UART transport. The blog contains the necessary packages to install, the commands to be send to configure the Ubuntu Host

 

 

Pre-requisites

-- CYW920706WCDEVAL Board (recommended to download an empty Application)

-- Linux System/  Linux Machine (preferably Ubuntu)

 

 

Setting up the Host Machine

 

1. Plugging in the board

 

Plug in the CYW920706WCDEVAL board to the Host Linux Machine(in my case i used a Ubuntu Laptop). Check the dmesg logs to see the device files generated to which the UART transport has bound. In my case, the CYW920706WCDEVAL board had a PUART and HCI UART. Hence, the dmesg displayed two device files.

Eg: dmesg log for enumeration

enumeration.png

 

If the dmesg logs didn't display the device files to which the board had bound, then it could be because the fdti LKM(loadable Kernel Module) was not loaded in the kernel during boot. You could manually add it using the following command.

>>> modprobe ftdi_sio

Check whether the VID and PID parameters of the USB device is getting added to the following file

>>>c/sys/bus/usb-serial/drivers/ftdi_sio/new_id

else add the PID and VID to the file the following location.

>>>echo <vid> <pid>  > /sys/bus/usb-serial/drivers/ftdi_sio/new_id

 

Replug the device back to the host machine and check the dmesg logs to see bonded device files.

After a reboot, the ftdio_sio LKM might get unloaded. To make the LKM load after every reboot, you could define a rule in the rules.d list.

To find about more about adding rules in the rules.d list , check the following page

https://unix.stackexchange.com/questions/226041/adding-usb-device-to-rules-d

 

2. Setting up BlueZ

 

Download the necessary packages for Bluez from the link given below and run the following commands. Additional packages  contains utilities to check the status of Bluez Daemon.

BlueZ » Download

>>>tar -xvf bluez-5.??.tar.xz
>>>cd bluez-5.??.tar.xz
>>>./configure
>>>make
>>>make install

Additional packages to download are given here.(if they are missing in your system).

>>>sudo apt-get install libdbus-1-dev libudev-dev libical-dev libreadline-dev bluetooth bluez-tools rfkill rfcomm

Once done with the download, check whether the Bluetooth adapter is unblocked.

>>> rfkill list all
>>> rfkill unblock all

Check the status of the corresponding systemd(system daemon) service:

>>>systemctl status bluetooth.service

The daemon can be reloaded with the following commands:

>>>systemctl daemon-reload
>>>systemctl restart bluetooth

3. HCI UART bring-up

 

Use hciattach command to attach the serial device via HCI UART to the BlueZ stack.

eg:

>>>sudo hciattach  /dev/ttyUSB0 -t 10 any 115200 noflow nosleep

 

The hciattach utility tries to send a HCI reset to the device via the HCI UART. Check the dmesg logs to see the status of HCI reset. If a reset timeout is happening, do a manual reset of the device while the reset commands are being send to the device by the host machine.

Once successful, you are ready to send the hci command using the hcitool utility.

The following picture shows dmesg logs for hciattach. Here, timeout is happening when host tries to send a HCI reset. This can be resolved by manually resetting the device.

timeout.png

Use the following command to check the hci devices

eg:

>>>hcitool dev 

Device:

          hci0      5C:AC:4C:F8:1F:80

          hci1      20:70:6A:20:f4:9B

The following diagram shows the commands to send to determine whether the device has been attached to the hci interface generated in the host.

It also gives further details like the BD address and the traffic the is going in the BT device.

hciconfig.png

For scanning LE devices:

>>> hcitool -i hci1 lescan

 

LE SCAN initiated in the interface hci1 created for the new device.

lescan.png

 

HCI command Injection

 

For sending specific HCI commands, use the following format:

>>>hcitool cmd <ogf> <ocf> [parameters]

 

eg: Write Local Name Command (ocf :HCI_Write_Local_Name -- 0x0013  & ogf: 0x03 )

For HCI Control and Baseband commands <ogf> is 0x03

(ABCD -- 0x41 0x42 0x43 0x44 )

The following picture show the usage of the hcitool cmd

hcicmd.png

Filter Blog

By date:
By tag: