Skip to content

Commit 8bb6cf4

Browse files
committed
net: l2: ieee802154: add support for IEEE802154_CFI_DATA_REQUEST
The 802.15.4 specifies that a device may send a DATA_REQUEST command to the coordinator macResponseWaitTime symbols after the acknowledgment to an association request command. This change adds proper support to generate DATA_REQUEST frames and sends one for the association usecase only. The two other usecases, for MLME-POLL or for beacon-enabled PAN, are not yet supported. Signed-off-by: Simon Piriou <[email protected]>
1 parent f1c2ce4 commit 8bb6cf4

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

subsys/net/l2/ieee802154/ieee802154_frame.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,37 @@ static inline bool cfi_to_fs_settings(enum ieee802154_cfi cfi, struct ieee802154
792792

793793
break;
794794
case IEEE802154_CFI_DATA_REQUEST:
795+
if (params->dst.len == 0) {
796+
/* If the Destination Addressing Mode subfield is set to zero (i.e.,
797+
* destination addressing information not present), the PAN ID
798+
* Compression subfield of the Frame Control field shall be set to zero
799+
* and the source PAN identifier shall contain the value of macPANId.
800+
*
801+
* This is the case only if the data request command is being
802+
* sent in response to the receipt of a beacon frame indicating that
803+
* data are pending for that device.
804+
*/
805+
fs->fc.dst_addr_mode = IEEE802154_ADDR_MODE_NONE;
806+
} else {
807+
/* Both short and extended dest addresses are supported.
808+
* It's up to the caller to configure it correctly.
809+
*/
810+
if (params->dst.len == IEEE802154_SHORT_ADDR_LENGTH) {
811+
fs->fc.dst_addr_mode = IEEE802154_ADDR_MODE_SHORT;
812+
} else {
813+
fs->fc.dst_addr_mode = IEEE802154_ADDR_MODE_EXTENDED;
814+
}
815+
fs->fc.pan_id_comp = 1U;
816+
}
817+
818+
if (params->short_addr == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED) {
819+
fs->fc.src_addr_mode = IEEE802154_ADDR_MODE_EXTENDED;
820+
} else {
821+
fs->fc.dst_addr_mode = IEEE802154_ADDR_MODE_SHORT;
822+
}
823+
824+
/* the Acknowledgment Request subfield is always set */
795825
fs->fc.ar = 1U;
796-
/* TODO: src/dst addr mode: see section 7.5.5 */
797826

798827
break;
799828
case IEEE802154_CFI_ORPHAN_NOTIFICATION:

subsys/net/l2/ieee802154/ieee802154_mgmt.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,30 @@ static int ieee802154_associate(uint64_t mgmt_request, struct net_if *iface,
574574
* TODO: The Association Response command shall be sent to the device
575575
* requesting association using indirect transmission.
576576
*/
577-
k_sem_take(&ctx->scan_ctx_lock, K_USEC(ieee802154_get_response_wait_time_us(iface)));
577+
ret = k_sem_take(&ctx->scan_ctx_lock, K_USEC(ieee802154_get_response_wait_time_us(iface)));
578+
579+
if (ret == -EAGAIN) {
580+
/* Timeout, send DATA_REQUEST */
581+
net_pkt_unref(pkt);
582+
pkt = ieee802154_create_mac_cmd_frame(
583+
iface, IEEE802154_CFI_DATA_REQUEST, &params);
584+
if (!pkt) {
585+
ret = -ENOBUFS;
586+
k_sem_give(&ctx->scan_ctx_lock);
587+
NET_ERR("Could not associate: cannot allocate DATA request frame");
588+
goto out;
589+
}
590+
ieee802154_mac_cmd_finalize(pkt, IEEE802154_CFI_DATA_REQUEST);
591+
592+
if (ieee802154_radio_send(iface, pkt, pkt->buffer)) {
593+
ret = -EIO;
594+
k_sem_give(&ctx->scan_ctx_lock);
595+
NET_ERR("Could not associate: cannot send DATA request");
596+
goto out;
597+
}
598+
599+
k_sem_take(&ctx->scan_ctx_lock, K_USEC(ieee802154_get_response_wait_time_us(iface)));
600+
}
578601

579602
/* Release the scan lock in case an association response was not received
580603
* within macResponseWaitTime and we got a timeout instead.
@@ -607,6 +630,7 @@ static int ieee802154_associate(uint64_t mgmt_request, struct net_if *iface,
607630
}
608631

609632
ctx->channel = req->channel;
633+
ret = 0;
610634
} else {
611635
ret = -EACCES;
612636
}

0 commit comments

Comments
 (0)