Skip to content

Commit 251f016

Browse files
wpanusb: fixes for beagleconnect freedom gateway (#5)
* get valid channels from device * disable IEEE802154_HW_PROMISCUOUS mode to disable error is kernel logs * with the changes Sub-G(with zephyr patch for PA) works without issues * 2.4G fails at setting channel * add simple rmmod script to remove assosciated modules, useful during driver testing Signed-off-by: vaishnav98 <[email protected]>
1 parent 7ba5f3d commit 251f016

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

scripts/rmmod.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
rmmod wpanusb
4+
rmmod ieee802154_6lowpan
5+
rmmod ieee802154_socket
6+
rmmod mac802154
7+
rmmod ieee802154
8+

wpanusb.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define WPANUSB_ALLOC_DELAY_MS 100 /* delay after failed allocation */
2626

2727
#define VENDOR_OUT (USB_TYPE_VENDOR | USB_DIR_OUT)
28+
#define VENDOR_IN (USB_TYPE_VENDOR | USB_DIR_IN)
2829

2930
#define WPANUSB_VALID_CHANNELS (0x07FFFFFF)
3031

@@ -56,6 +57,17 @@ static int wpanusb_control_send(struct wpanusb *wpanusb, unsigned int pipe,
5657
0, 0, data, size, 1000);
5758
}
5859

60+
static int wpanusb_control_recv(struct wpanusb *wpanusb, u8 request, void *data, u16 size)
61+
{
62+
struct usb_device *udev = wpanusb->udev;
63+
64+
usb_control_msg(udev, usb_sndctrlpipe(udev, 0), request, VENDOR_OUT,
65+
0, 0, NULL, 0, 1000);
66+
67+
return usb_control_msg(udev, usb_rcvbulkpipe(udev, 1), request, VENDOR_IN,
68+
0, 0, data, size, 1000);
69+
}
70+
5971
/* ----- skb allocation ---------------------------------------------------- */
6072

6173
#define MAX_PSDU 127
@@ -448,6 +460,7 @@ static int wpanusb_get_device_capabilities(struct ieee802154_hw *hw)
448460
struct wpanusb *wpanusb = hw->priv;
449461
struct usb_device *udev = wpanusb->udev;
450462
unsigned char *buffer;
463+
uint32_t valid_channels;
451464
int ret = 0;
452465

453466
buffer = kmalloc(IEEE802154_EXTENDED_ADDR_LEN, GFP_KERNEL);
@@ -463,18 +476,31 @@ static int wpanusb_get_device_capabilities(struct ieee802154_hw *hw)
463476
return ret;
464477
}
465478

479+
buffer = kmalloc(sizeof(valid_channels), GFP_NOIO);
480+
if (!buffer)
481+
return -ENOMEM;
482+
ret = wpanusb_control_recv(wpanusb, GET_SUPPORTED_CHANNELS, buffer, sizeof(valid_channels));
483+
if (ret != sizeof(uint32_t)) {
484+
dev_err(&udev->dev, "failed to fetch supported channels\n");
485+
kfree(buffer);
486+
return ret;
487+
}
488+
valid_channels = *(uint32_t *)buffer;
489+
if (!valid_channels) {
490+
dev_err(&udev->dev, "failed to fetch valid channels, setting default valid channels\n");
491+
valid_channels = WPANUSB_VALID_CHANNELS;
492+
}
493+
466494
/* FIXME: these need to come from device capabilities */
467-
hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT |
468-
IEEE802154_HW_PROMISCUOUS;
495+
hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT;
469496

470497
/* FIXME: these need to come from device capabilities */
471498
hw->phy->flags = WPAN_PHY_FLAG_TXPOWER;
472499

473500
/* Set default and supported channels */
474501
hw->phy->current_page = 0;
475-
hw->phy->current_channel = 11;
476-
/* FIXME: these need to come from device capabilities */
477-
hw->phy->supported.channels[0] = WPANUSB_VALID_CHANNELS;
502+
hw->phy->current_channel = ffs(valid_channels) - 1; //set to lowest valid channel
503+
hw->phy->supported.channels[0] = valid_channels;
478504

479505
/* FIXME: these need to come from device capabilities */
480506
hw->phy->supported.tx_powers = wpanusb_powers;

wpanusb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum wpanusb_requests {
3232
SET_FRAME_RETRIES,
3333
SET_PROMISCUOUS_MODE,
3434
GET_EXTENDED_ADDR,
35-
GET_CAPABILITIES,
35+
GET_SUPPORTED_CHANNELS,
3636
};
3737

3838
struct set_channel {

0 commit comments

Comments
 (0)