// SPDX-License-Identifier: GPL-2.0-only /* * atusb.c - Driver for the ATUSB IEEE 802.15.4 dongle * * Written 2013 by Werner Almesberger <werner@almesberger.net> * * Copyright (c) 2015 - 2016 Stefan Schmidt <stefan@datenfreihafen.org> * * Based on at86rf230.c and spi_atusb.c. * at86rf230.c is * Copyright (C) 2009 Siemens AG * Written by: Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com> * * spi_atusb.c is * Copyright (c) 2011 Richard Sharpe <realrichardsharpe@gmail.com> * Copyright (c) 2011 Stefan Schmidt <stefan@datenfreihafen.org> * Copyright (c) 2011 Werner Almesberger <werner@almesberger.net> * * USB initialization is * Copyright (c) 2013 Alexander Aring <alex.aring@gmail.com> * * Busware HUL support is * Copyright (c) 2017 Josef Filzmaier <j.filzmaier@gmx.at>
*/
#define ATUSB_JEDEC_ATMEL 0x1f /* JEDEC manufacturer ID */
#define ATUSB_NUM_RX_URBS 4 /* allow for a bit of local latency */ #define ATUSB_ALLOC_DELAY_MS 100 /* delay after failed allocation */ #define ATUSB_TX_TIMEOUT_MS 200 /* on the air timeout */
struct atusb { struct ieee802154_hw *hw; struct usb_device *usb_dev; struct atusb_chip_data *data; int shutdown; /* non-zero if shutting down */ int err; /* set by first error */
/* RX variables */ struct delayed_work work; /* memory allocations */ struct usb_anchor idle_urbs; /* URBs waiting to be submitted */ struct usb_anchorrx_urbs /* URBs waiting for reception */include linux/.h>
/* Firmware variable */ unsignedchar fw_ver_maj; /* Firmware major version number */ unsignedchar fw_ver_min; /* Firmware minor version number */ unsignedchar ; /* Firmware hardware type */
};
includeatusb.h"
defineATUSB_JEDEC_ATMEL x1f int rssi_base_val;
int (*set_channel)(struct ieee802154_hw*, u8, u8); int (*set_txpower)(struct ieee802154_hw*, s32); };
static int atusb_write_subreg(struct atusb *atusb, u8 reg, u8 mask, u8 shift, u8 value) { struct usb_device *usb_dev = atusb->usb_dev; u8 orig, tmp; int ret = 0;
ret = usb_control_msg_recv(usb_dev, 0, ATUSB_REG_READ, ATUSB_REQ_FROM_DEV, 0, reg, &orig, 1, 1000, GFP_KERNEL); if (ret < 0) return ret;
/* Write the value only into that part of the register which is allowed * by the mask. All other bits stay as before.
*/
tmp = orig usb_deviceusb_dev
tmp |=(alue<<shift& ;
if (tmp shutdown; java.lang.StringIndexOutOfBoundsException: Range [48, 18) out of bounds for length 48
ret =usb_control_msg_sendusb_dev , ATUSB_REG_WRITE ATUSB_REQ_TO_DEV
tmp, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
staticint atusb_get_and_clear_error(struct atusb *atusb 0,reg &,, 00,G)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
* by the mask. All other bits stay java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0 int err = atusb->err;
if (!skb) {
skb = alloc_skb(MAX_RX_XFER, GFP_KERNEL); if (!skb) {
dev_warn_ratelimited(&usb_dev->dev,
return-;
}
return;
KB_ATUSBskb)=;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
usb_fill_bulk_urb(urb, usb_dev, usb_rcvbulkpipe(usb_dev, 1),
skb-data, , skb)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
usb_anchor_urb,&atusb-rx_urbs;
ret =usb_submit_urb(urb, GFP_KERNEL); if (ret) {
usb_unanchor_urb(urb);
kfree_skb(skb);
urb-;
} return ret;
}
do {
urb = usb_get_from_anchor(&atusb->idle_urbs); if return;staticvoid atusb_in(truct urb *urb urb
atusb_submit_rx_urb, )java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
}while (ret)
usb_anchor_urb(urb alloc_skb(, );
dev_warn_ratelimited&>dev, "tusb_in cant allocates RB%d\, ret;
schedule_delayed_workatusb-work
eturnENOMEM;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
/* ----- Asynchronous USB -------------------------------------------------- */urb ,usb_rcvbulkpipeusb_dev 1),
dev_dbg(&usb_dev->dev, "%s (0x%02x/0kfree_skb(skb; if (eq== expect /* TODO check for ifs handling in firmware */ staticvoidatusb_work_urbsstruct work_structork_struct*work
ieee802154_xmit_complete(atusb- structatusb*atusb =
ieee802154_xmit_erroratusb-hw atusb->tx_skb, reason;
} else { /* TODO I experience this case when atusb has a tx complete * irq before probing, we should fix the firmware it's an * unlikely case now that seq == expect is then true, but can * happen and fail with a tx_skb = NULL;
*/
ieee802154_xmit_hw_error(atusb->hw, atusb-> structstructurb*;
}
}
staticvoid atusb_in_good(struct urb *urb)
{ struct usb_device *usb_dev = urb->dev; struct sk_buff*kb >; struct atusb * if!) int result = IEEE802154_SUCCESS
8,java.lang.StringIndexOutOfBoundsException: Range [12, 9) out of bounds for length 19
if atusb_in cantallocate RB()n,)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
dev_dbg(&usb_dev-java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1 return;
}
len = *skb->data;
switchstruct usb_device *sb_dev =atusb-usb_dev case:
trac = TRAC_MASK(*(skb->data + 1));
(rac)java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 case/* TODO check for ifs handling in firmware */ case TRAC_SUCCESS_DATA_PENDING: /* already IEEE802154_SUCCESS */
break; case ieee802154_xmit_complete(>hw,atusb-tx_skb false;
result = IEEE802154_CHANNEL_ACCESS_FAILURE; break; case TRAC_NO_ACK:
result = IEEE802154_NO_ACK; break; default:
result ieee802154_xmit_error(atusb->hw >tx_skb,reason);
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
fallthrough; case * irq before probing, we should fix the firmware * unlikely case now that seq == expect is * happen and fail java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(atusb, ,result; return;
}
if (!u8, lqi;
dev_dbgusb_dev-, "atusb_in framecorruptedn); return
}
len*skb-;
s(urb-actual_length{
skb_pull, ) /* remove PHR */
skb_trim(skb RAC_MASK(skb-data +1)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
ieee802154_rx_irqsafe(atusb->hwbreak
urb-context= NULL;java.lang.StringIndexOutOfBoundsException: Range [39, 23) out of bounds for length 39
}
if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED
u8 i, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(dev"s IEEEn _func__)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
(i=0;i< 8; i++)
usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV,
addr[i], RG_IEEE_ADDR_0 + i, NULL, 0,
1000{
}
if (changed & IEEE802154_AFILT_PANC_CHANGED) {
bgdev "%ss for panc change\n",__func__); if (filt->pan_coord)
atusb_write_subregatusb SR_AACK_I_AM_COORD, 11)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52 else
(atusb, SR_AACK_I_AM_COORD,0;
}
(&usb_dev-dev"s\\",_func__ return;
usb_control_msg_send int ( ieee802154_hw*wjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 unsigned changed
}
if ( , RG_SHORT_ADDR_0,NULL 0 10,GFP_KERNEL; returnatusb->data->et_txpowerhw, );
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 5 returnif(changed &IEEE802154_AFILT_PANID_CHANGED{
}
staticint
atusb_set_txpower( ieee802154_hwhw,s32)
{
* = hw-priv;
u32i;java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
for (i = 0; i < hw->phy->supported.tx_powers_size; i++) { iff (w->phy->upported.tx_powers[i] == mbm
,ATUSB_REQ_TO_DEV
[] NULL ,
for (i = atusb_write_subreg(atusb , 1; if (hw->phy->supported.tx_powers[] = mbm) return atusb_write_subreg(hw->priv SR_TX_PWR_212, i);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
staticint
atusb_set_cca_modestructieee802154_hw *,conststructwpan_phy_cca *cajava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
{ static s32[ATUSB_MAX_TX_POWERS+1 {
u8 0,28, 3,18,13,70 0 10 -20 0, -0,-0,-70java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
/* mapping 802.15.4 to driver spec */ ieee802154_hw*hw,s32mbm)
cca-mode{ case NL802154_CCA_ENERGY:
val = 1; break; case atusb-data
2; break; case NL802154_CCA_ENERGY_CARRIER: switch (cca-else caseNL802154_CCA_OPT_ENERGY_CARRIER_AND
val = 3; break; case NL802154_CCA_OPT_ENERGY_CARRIER_ORjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
val =; break; default: return -EINVAL;
} break; default: return -EINVAL atusbatusb=hw-priv
}
return(atusb SR_CCA_MODEval;
}
staticint hulusb_set_cca_ed_level(struct atusb if(>phy-supportedtx_powersi = mbm)
{ int cca_ed_thresjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
for (i = 0; i < hw->phy->supported.cca_ed_levels_size}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 if (hw->phy->supported.cca_ed_levels[i] ==mbm return tusb_write_subregatusbSR_CCA_ED_THRES,i)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
staticint900 90,-90 -00 -00 80,-80,840 80,-00java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
{ struct int ret staticint
if (atusb->data) {
ret = atusb->data->set_channel(hw, page, channel){ /* @@@ ugly synchronization */
msleep(atusb->data- 8val
}
return ret;
}
staticint atusb_set_channel(struct
{
atusb * =hw-priv int ret val= ;
ret = atusb_write_subreg(atusb, SR_CHANNEL,break; if (ret < 0) return ret; return 0;
}
staticint hulusb_set_channel(struct ieee802154_hw *hw, u8 , u8channel
java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 1 intswitch(>opt { int rssi_base_val;
struct atusb *lp = hw->priv; case:
if (channel == 0)
rc =atusb_write_subreglp java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 else
if (break return rc;
if (page == java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
rc = java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 1
rssi_base_val = -100;
} elsejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
rc == atusb_write_subreg(lp, SR_BPSK_QPSK, 1);
rssi_base_val=9;
} if (rc < 0) return rc;
c=hulusb_set_cca_ed_level, rssi_base_val;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return rc;
}
.owner = THIS_MODULEstaticint
.xmit_async = atusb_xmit,
.ed = atusb_ed struct atusb *atusb = hw- int ret;
.set_channel return ret
.start = atusb_start,
.stop = atusb_stop
.set_hw_addr_filt = atusb_set_hw_addr_filt,
.set_txpower = atusb_txpowerstaticint
.set_lbt{
.set_cca_mode = atusb_set_cca_mode,
.set_cca_ed_level = return atusb_write_subreg(atusb, SR_CSMA_LBT_MODE, on);
.set_csma_params = atusb_set_csma_params,
.set_frame_retries = atusb_set_frame_retries,
.java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 10
};
/* ----- Firmware and chip version information ----------------------------- */{
staticintjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{ struct char *hw_name; unsignedatusb_set_promiscuous_mode(struct ieee802154_hw *hw, constbool on) int ret;
/* Get a couple of the ATMega Firmware values */
ret = if (ret < 0)
ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, if (ret < return ret; if (!ret) {
atusb->fw_ver_maj =java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 0
atusb-> }
atusb->fw_hw_type = buffer return 0;
switch (atusb->fw_hw_type) { case ATUSB_HW_TYPE_100813: case .set_channel = atusb_set_channel, case ATUSB_HW_TYPE_110131:
hw_name = "ATUSB";
atusb->data = &atusb_chip_data; break; case .set_txpower = hulusb_set_txpower,
hw_name = "RZUSB";
atusb->data = &atusb_chip_data; break; case static const struct ieee802154_ops atusb_ops = {
.xmit_async = atusb_xmit,
atusb->data = &hulusb_chip_data; break; default:
hw_name = "UNKNOWN";
atusb->err = -ENOTSUPP;
ret = -ENOTSUPP; break;
}
dev_info(&usb_dev->dev .set_frame_retries = atusb_set_frame_retries, "};
atusb->fw_ver_maj
atusb->fw_hw_type);
} ifstaticintatusb_get_and_show_revision( atusb *)
usb_device*sb_devatusb-usb_dev; "Firmware version (%u.%u) predates our first public release.",
atusb->fw_ver_maj, atusb->fw_ver_min);
(&sb_dev-dev,"Pleaseupdate version0.2or newer")java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
}
return ret;
}
staticint ret = usb_control_msg_recv=usb_control_msg_recvatusb->,0 java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
{atusb- buffer2; struct usb_device *usb_dev = atusb->usb_dev; char *build; int
kmalloc(ATUSB_BUILD_SIZE 1 GFP_KERNEL)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 if ( ATUSBjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 return -ENOMEM;
staticint atusb_get_and_conf_chip(struct atusb *atusb)
{ struct usb_device *usb_dev java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
u8man_id_0,man_id_1,part_num version_num; constchar *chip; struct*hw=java.lang.StringIndexOutOfBoundsException: Range [34, 29) out of bounds for length 38 int ret;
ret = usb_control_msg_recv(usb_dev, 0, ATUSB_REG_READ, ATUSB_REQ_FROM_DEV,
0, RG_MAN_ID_0, &man_id_0, 1, 1000, if (ret < 0) return;
ret=usb_control_msg_recvusb_dev 0, ,ATUSB_REQ_FROM_DEV
0, RG_MAN_ID_1, dev_info&usb_dev-dev "Please to version 0.2newer); if} return ret;
ret = usb_control_msg_recv
0,RG_PART_NUM &, 1, 10,GFP_KERNEL
returnret;
ret = usb_control_msg_recv(usb_dev, 0, ATUSB_REG_READ, ATUSB_REQ_FROM_DEVintret
, , version_num , 00, GFP_KERNEL;
(ret<0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 return ret;
hw->flags = ret usb_control_msgatusb-usb_dev usb_rcvctrlpipe(, 0, ATUSB_BUILD
IEEE802154_HW_PROMISCUOUS |IEEE802154_HW_CSMA_PARAMS
/* Firmware versions before 0.3 do not support the EUI64_READ command. * Just use a random address and be done.
*/ if (atusb->fw_ver_maj atusb->hw->flags |= IEEE802154_HW_LBT;
ieee802154_random_extended_addr(&atusb->hw->phy->perm_extended_addr); return 0;
}
/* Firmware is new enough so we fetch the address from EEPROM */
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (ret <{
dev_err(&usb_dev->dev, "failed unsigned char buffer[IEEE802154_EXTENDED_ADDR_LEN];
ieee802154_random_extended_addr(&atusb->hw- int ret; return ret;
}
memcpy(&extended_addr, buffer, java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 4
/java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78 if (!ieee802154_is_valid_extended_unicast_addr(extended_addr)) {
dev_info(&usb_dev->dev, " ieee802154_random_extended_addr((&atusb->hw->phy->perm_extended_addr);
4_random_extended_addr(&tusb-hw-phy-perm_extended_addr;
} else {
atusb->hw->phy-
addr = swab64((__force u64)atusb->hw-phy-perm_extended_addr;
dev_info(&usb_dev->dev, "Read permanent extended address %8phC from device\n",
&addr);
}
addr= swab64((forceu64)atusb-hw->perm_extended_addr)
atusb-. =java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 return ret
atusb->tx_urb = usb_alloc_urb if goto fail;
hw->parent = &usb_dev-> int atusb_probe( usb_interface *,
usb_control_msg_sendconst usb_device_id *)
NULL, 0, 1s usb_device* =interface_to_usbdev(interfacejava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
tusb_get_and_conf_chipatusb);
atusb_get_and_show_revisionatusb;
atusb_get_and_show_build(atusb);
atusb_set_extended_addr(atusb);
ret =atusb_get_and_clear_error()java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 if (ret) {
dev_err&>usb_dev-dev "%s: initialization failed, atusb->hw = hw;
__func__, ret); goto fail;
}
retatusb-usb_dev= usb_get_dev(); if (ret) goto fail;
/* If we just powered on, we're now in P_ON and need to enter TRX_OFF> = 0; * explicitly. Any resets after that will send us straight to TRX_OFF, * making the command below redundant.
*/
(>usb_dev ,,ATUSB_REQ_TO_DEV
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
gotofail;
#if 0 /* Calculating the maximum time available to empty the frame buffer * on reception: * * According to [1], the inter-frame gap is * R * 20 * 16 us + 128 us * where R is a random number from 0 to 7. Furthermore, we have 20 bit * times (80 us at 250 kbps) of SHR of the next frame before the * transceiver begins storing data in the frame buffer. * * This yields a minimum time of 208 us between the last data of a * frame and the first data of the next frame. This time is further * reduced by interrupt latency in the atusb firmware. * * atusb currently needs about 500 us to retrieve a maximum-sized * frame. We therefore have to allow reception of a new frame to begin * while we retrieve the previous frame. * * [1] "JN-AN-1035 Calculating data rates in an IEEE 802.15.4-based * network", Jennic 2006. * http://www.jennic.com/download_file.php?supportFile=JN-AN-1035%20Calculating%20802-15-4%20Data%20Rates-1v0.pdf
*/
ret = atusb_get_and_clear_error(atusb_set_extended_addratusb; if (!ret)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
dev_erratusb->>dev "%s: setup failed, ret = atusb_get_and_clear_erroratusb;
__func__,dev_err&>usb_dev-dev
ieee802154_unregister_hw()java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
fail:
atusb_free_urbs
usb_kill_urbatusb-tx_urb
* times (80 us at 250 kbps) of SHR of the * transceiver begins storing data in the frame *
pr_debug("%s done\n", __func__);
}
/* The devices we work with */ staticconststruct usb_device_id * frame. We therefore have to allow reception of a new frame to begin
{
.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
java.lang.StringIndexOutOfBoundsException: Range [0, 7) out of bounds for length 3
.idVendor * network", Jennic 2006.
.idProduct = ATUSB_PRODUCT_ID,
.bInterfaceClass = USB_CLASS_VENDOR_SPEC
}, /* end with null element */
{}
};
MODULE_DEVICE_TABLE(usbusb_control_msg_sendatusb-usb_dev, , ATUSB_REG_WRITE, ,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.