blob: 8f7818f2321a9fbf853d1b11a35a14b6c5e9ca25 [file] [log] [blame]
Tomasz Bursztykac3ce0282016-06-14 10:52:57 +02001/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Tomasz Bursztykac3ce0282016-06-14 10:52:57 +02005 */
6
Jukka Rissanen68ea9372016-11-12 00:13:24 +02007/**
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 Bursztyka4a3afb82017-12-07 10:13:56 +010017#include <net/ieee802154.h>
Jukka Rissanen68ea9372016-11-12 00:13:24 +020018
Jukka Rissanen68ced802017-07-24 16:23:14 +030019#ifdef __cplusplus
20extern "C" {
21#endif
22
Jukka Rissanen539b0c42017-07-20 16:29:45 +030023/**
24 * @addtogroup ieee802154
25 * @{
26 */
27
Tomasz Bursztyka9c460552017-09-04 13:06:49 +020028enum 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 Bursztyka7f04af82017-10-03 10:32:59 +020034 IEEE802154_HW_TX_RX_ACK = BIT(5), /* Handles ACK request on TX */
Tomasz Bursztyka9c460552017-09-04 13:06:49 +020035};
36
Tomasz Bursztyka3d63a342017-09-05 13:50:36 +020037enum ieee802154_filter_type {
38 IEEE802154_FILTER_TYPE_IEEE_ADDR,
39 IEEE802154_FILTER_TYPE_SHORT_ADDR,
40 IEEE802154_FILTER_TYPE_PAN_ID,
41};
42
43struct 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 Rissanen68ea9372016-11-12 00:13:24 +020053struct 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 Bursztyka9c460552017-09-04 13:06:49 +020062 /** Get the device capabilities */
63 enum ieee802154_hw_caps (*get_capabilities)(struct device *dev);
64
Jukka Rissanen68ea9372016-11-12 00:13:24 +020065 /** Clear Channel Assesment - Check channel's activity */
66 int (*cca)(struct device *dev);
67
68 /** Set current channel */
Kumar Galaa5094412017-04-21 09:27:50 -050069 int (*set_channel)(struct device *dev, u16_t channel);
Jukka Rissanen68ea9372016-11-12 00:13:24 +020070
Tomasz Bursztyka3d63a342017-09-05 13:50:36 +020071 /** 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 Rissanen68ea9372016-11-12 00:13:24 +020076 /** Set TX power level in dbm */
Kumar Galaa5094412017-04-21 09:27:50 -050077 int (*set_txpower)(struct device *dev, s16_t dbm);
Jukka Rissanen68ea9372016-11-12 00:13:24 +020078
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +020079 /** Transmit a packet fragment */
Tomasz Bursztyka83ed3a22017-01-26 14:31:30 +010080 int (*tx)(struct device *dev,
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +020081 struct net_pkt *pkt,
Tomasz Bursztyka83ed3a22017-01-26 14:31:30 +010082 struct net_buf *frag);
Jukka Rissanen68ea9372016-11-12 00:13:24 +020083
84 /** Start the device */
85 int (*start)(struct device *dev);
86
87 /** Stop the device */
88 int (*stop)(struct device *dev);
Jukka Rissanen68ea9372016-11-12 00:13:24 +020089} __packed;
90
91/**
Tomasz Bursztykab52c0f22017-11-16 11:11:51 +010092 * @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 */
98bool ieee802154_is_ar_flag_set(struct net_pkt *pkt);
99
100#ifndef CONFIG_IEEE802154_RAW_MODE
101
102/**
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200103 * @brief Radio driver sending function that hw drivers should use
104 *
Jukka Rissanenb6a5d512017-08-08 14:41:23 +0300105 * @details This function should be used to fill in struct net_if's send
106 * pointer.
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200107 *
108 * @param iface A valid pointer on a network interface to send from
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +0200109 * @param pkt A valid pointer on a packet to send
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200110 *
111 * @return 0 on success, negative value otherwise
112 */
113extern int ieee802154_radio_send(struct net_if *iface,
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +0200114 struct net_pkt *pkt);
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200115
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. Kinderfc5f2b32017-05-02 17:21:56 -0700120 * helps to hook directly the hw drivers to the radio driver.
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200121 *
122 * @param iface A valid pointer on a network interface that received the packet
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +0200123 * @param pkt A valid pointer on a packet to check
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200124 *
125 * @return NET_OK if it was handled, NET_CONTINUE otherwise
126 */
127extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
Tomasz Bursztykadb11fcd2017-04-05 08:37:44 +0200128 struct net_pkt *pkt);
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200129
130/**
131 * @brief Initialize L2 stack for a given interface
132 *
133 * @param iface A valid pointer on a network interface
134 */
135void ieee802154_init(struct net_if *iface);
136
Tomasz Bursztykab52c0f22017-11-16 11:11:51 +0100137#else /* CONFIG_IEEE802154_RAW_MODE */
Tomasz Bursztyka811db9a2017-10-09 11:49:28 +0200138
Tomasz Bursztykab52c0f22017-11-16 11:11:51 +0100139static inline int ieee802154_radio_send(struct net_if *iface,
140 struct net_pkt *pkt)
141{
142 return 0;
143}
144
145static 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 Bursztyka811db9a2017-10-09 11:49:28 +0200154
Jukka Rissanen68ced802017-07-24 16:23:14 +0300155#ifdef __cplusplus
156}
157#endif
158
Jukka Rissanen539b0c42017-07-20 16:29:45 +0300159/**
160 * @}
161 */
162
Jukka Rissanen68ea9372016-11-12 00:13:24 +0200163#endif /* __IEEE802154_RADIO_H__ */