Tomasz Bursztyka | c3ce028 | 2016-06-14 10:52:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Intel Corporation. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Tomasz Bursztyka | c3ce028 | 2016-06-14 10:52:57 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 7 | /** |
| 8 | * @file |
| 9 | * @brief Public IEEE 802.15.4 Radio API |
| 10 | */ |
| 11 | |
| 12 | #ifndef __IEEE802154_RADIO_H__ |
| 13 | #define __IEEE802154_RADIO_H__ |
| 14 | |
| 15 | #include <device.h> |
| 16 | #include <net/net_if.h> |
Tomasz Bursztyka | 4a3afb8 | 2017-12-07 10:13:56 +0100 | [diff] [blame] | 17 | #include <net/ieee802154.h> |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 18 | |
Jukka Rissanen | 68ced80 | 2017-07-24 16:23:14 +0300 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Jukka Rissanen | 539b0c4 | 2017-07-20 16:29:45 +0300 | [diff] [blame] | 23 | /** |
| 24 | * @addtogroup ieee802154 |
| 25 | * @{ |
| 26 | */ |
| 27 | |
Tomasz Bursztyka | 9c46055 | 2017-09-04 13:06:49 +0200 | [diff] [blame] | 28 | enum ieee802154_hw_caps { |
| 29 | IEEE802154_HW_FCS = BIT(0), /* Frame Check-Sum supported */ |
| 30 | IEEE802154_HW_PROMISC = BIT(1), /* Promiscuous mode supported */ |
| 31 | IEEE802154_HW_FILTER = BIT(2), /* Filters PAN ID, long/short addr */ |
| 32 | IEEE802154_HW_CSMA = BIT(3), /* CSMA-CA supported */ |
| 33 | IEEE802154_HW_2_4_GHZ = BIT(4), /* 2.4Ghz radio supported */ |
Tomasz Bursztyka | 7f04af8 | 2017-10-03 10:32:59 +0200 | [diff] [blame] | 34 | IEEE802154_HW_TX_RX_ACK = BIT(5), /* Handles ACK request on TX */ |
Tomasz Bursztyka | 9c46055 | 2017-09-04 13:06:49 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Tomasz Bursztyka | 3d63a34 | 2017-09-05 13:50:36 +0200 | [diff] [blame] | 37 | enum ieee802154_filter_type { |
| 38 | IEEE802154_FILTER_TYPE_IEEE_ADDR, |
| 39 | IEEE802154_FILTER_TYPE_SHORT_ADDR, |
| 40 | IEEE802154_FILTER_TYPE_PAN_ID, |
| 41 | }; |
| 42 | |
| 43 | struct ieee802154_filter { |
| 44 | /** @cond ignore */ |
| 45 | union { |
| 46 | u8_t *ieee_addr; |
| 47 | u16_t short_addr; |
| 48 | u16_t pan_id; |
| 49 | }; |
| 50 | /* @endcond */ |
| 51 | }; |
| 52 | |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 53 | struct ieee802154_radio_api { |
| 54 | /** |
| 55 | * Mandatory to get in first position. |
| 56 | * A network device should indeed provide a pointer on such |
| 57 | * net_if_api structure. So we make current structure pointer |
| 58 | * that can be casted to a net_if_api structure pointer. |
| 59 | */ |
| 60 | struct net_if_api iface_api; |
| 61 | |
Tomasz Bursztyka | 9c46055 | 2017-09-04 13:06:49 +0200 | [diff] [blame] | 62 | /** Get the device capabilities */ |
| 63 | enum ieee802154_hw_caps (*get_capabilities)(struct device *dev); |
| 64 | |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 65 | /** Clear Channel Assesment - Check channel's activity */ |
| 66 | int (*cca)(struct device *dev); |
| 67 | |
| 68 | /** Set current channel */ |
Kumar Gala | a509441 | 2017-04-21 09:27:50 -0500 | [diff] [blame] | 69 | int (*set_channel)(struct device *dev, u16_t channel); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 70 | |
Tomasz Bursztyka | 3d63a34 | 2017-09-05 13:50:36 +0200 | [diff] [blame] | 71 | /** Set address filters (for IEEE802154_HW_FILTER ) */ |
| 72 | int (*set_filter)(struct device *dev, |
| 73 | enum ieee802154_filter_type type, |
| 74 | const struct ieee802154_filter *filter); |
| 75 | |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 76 | /** Set TX power level in dbm */ |
Kumar Gala | a509441 | 2017-04-21 09:27:50 -0500 | [diff] [blame] | 77 | int (*set_txpower)(struct device *dev, s16_t dbm); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 78 | |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 79 | /** Transmit a packet fragment */ |
Tomasz Bursztyka | 83ed3a2 | 2017-01-26 14:31:30 +0100 | [diff] [blame] | 80 | int (*tx)(struct device *dev, |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 81 | struct net_pkt *pkt, |
Tomasz Bursztyka | 83ed3a2 | 2017-01-26 14:31:30 +0100 | [diff] [blame] | 82 | struct net_buf *frag); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 83 | |
| 84 | /** Start the device */ |
| 85 | int (*start)(struct device *dev); |
| 86 | |
| 87 | /** Stop the device */ |
| 88 | int (*stop)(struct device *dev); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 89 | } __packed; |
| 90 | |
| 91 | /** |
Tomasz Bursztyka | b52c0f2 | 2017-11-16 11:11:51 +0100 | [diff] [blame] | 92 | * @brief Check if AR flag is set on the frame inside given net_pkt |
| 93 | * |
| 94 | * @param pkt A valid pointer on a net_pkt structure, must not be NULL. |
| 95 | * |
| 96 | * @return True if AR flag is set, False otherwise |
| 97 | */ |
| 98 | bool ieee802154_is_ar_flag_set(struct net_pkt *pkt); |
| 99 | |
| 100 | #ifndef CONFIG_IEEE802154_RAW_MODE |
| 101 | |
| 102 | /** |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 103 | * @brief Radio driver sending function that hw drivers should use |
| 104 | * |
Jukka Rissanen | b6a5d51 | 2017-08-08 14:41:23 +0300 | [diff] [blame] | 105 | * @details This function should be used to fill in struct net_if's send |
| 106 | * pointer. |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 107 | * |
| 108 | * @param iface A valid pointer on a network interface to send from |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 109 | * @param pkt A valid pointer on a packet to send |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 110 | * |
| 111 | * @return 0 on success, negative value otherwise |
| 112 | */ |
| 113 | extern int ieee802154_radio_send(struct net_if *iface, |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 114 | struct net_pkt *pkt); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * @brief Radio driver ACK handling function that hw drivers should use |
| 118 | * |
| 119 | * @details ACK handling requires fast handling and thus such function |
David B. Kinder | fc5f2b3 | 2017-05-02 17:21:56 -0700 | [diff] [blame] | 120 | * helps to hook directly the hw drivers to the radio driver. |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 121 | * |
| 122 | * @param iface A valid pointer on a network interface that received the packet |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 123 | * @param pkt A valid pointer on a packet to check |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 124 | * |
| 125 | * @return NET_OK if it was handled, NET_CONTINUE otherwise |
| 126 | */ |
| 127 | extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface, |
Tomasz Bursztyka | db11fcd | 2017-04-05 08:37:44 +0200 | [diff] [blame] | 128 | struct net_pkt *pkt); |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * @brief Initialize L2 stack for a given interface |
| 132 | * |
| 133 | * @param iface A valid pointer on a network interface |
| 134 | */ |
| 135 | void ieee802154_init(struct net_if *iface); |
| 136 | |
Tomasz Bursztyka | b52c0f2 | 2017-11-16 11:11:51 +0100 | [diff] [blame] | 137 | #else /* CONFIG_IEEE802154_RAW_MODE */ |
Tomasz Bursztyka | 811db9a | 2017-10-09 11:49:28 +0200 | [diff] [blame] | 138 | |
Tomasz Bursztyka | b52c0f2 | 2017-11-16 11:11:51 +0100 | [diff] [blame] | 139 | static inline int ieee802154_radio_send(struct net_if *iface, |
| 140 | struct net_pkt *pkt) |
| 141 | { |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static inline enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface, |
| 146 | struct net_pkt *pkt) |
| 147 | { |
| 148 | return NET_CONTINUE; |
| 149 | } |
| 150 | |
| 151 | #define ieee802154_init(_iface_) |
| 152 | |
| 153 | #endif /* CONFIG_IEEE802154_RAW_MODE */ |
Tomasz Bursztyka | 811db9a | 2017-10-09 11:49:28 +0200 | [diff] [blame] | 154 | |
Jukka Rissanen | 68ced80 | 2017-07-24 16:23:14 +0300 | [diff] [blame] | 155 | #ifdef __cplusplus |
| 156 | } |
| 157 | #endif |
| 158 | |
Jukka Rissanen | 539b0c4 | 2017-07-20 16:29:45 +0300 | [diff] [blame] | 159 | /** |
| 160 | * @} |
| 161 | */ |
| 162 | |
Jukka Rissanen | 68ea937 | 2016-11-12 00:13:24 +0200 | [diff] [blame] | 163 | #endif /* __IEEE802154_RADIO_H__ */ |