mac_mcps_data.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef MAC_MCPS_DATA_H_INCLUDED
  43. #define MAC_MCPS_DATA_H_INCLUDED
  44. #include <stdint.h>
  45. #include "mac_common.h"
  46. #include "mac_task_scheduler.h"
  47. /** @file
  48. * The MAC Data module declares the MAC Data transmittion routines and necessary types
  49. * according to the MAC specification.
  50. *
  51. * @defgroup mac_data MAC MCPS Data API
  52. * @ingroup mac_15_4
  53. * @{
  54. * @brief Module to declare MAC MCPS Data API.
  55. * @details The MAC MCPS Data module declares the MAC Data transmission routines and necessary types according
  56. * to the MAC specification. More specifically, MAC data request mcps_data_req(), and MAC Data
  57. * indication mcps_data_ind() primitives are declared. The confirmation callback typedef is
  58. * declared as mcps_data_conf_cb_t.
  59. */
  60. /**
  61. * @brief TX options bit fields.
  62. *
  63. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.1.
  64. */
  65. #define TX_ACKNOWLEDGED_BIT (0)
  66. #define TX_GTS_BIT (1)
  67. #define TX_INDIRECT_BIT (2)
  68. /**
  69. * @brief TX options for MAC data transmission.
  70. *
  71. * @details The three bits (b0, b1, b2) indicate the transmission options for this MSDU.
  72. * For b0, 1 = acknowledged transmission, 0 = unacknowledged transmission.
  73. * For b1, 1 = GTS transmission, 0 = CAP transmission for a beacon-enabled PAN.
  74. * For b2, 1 = indirect transmission, 0 = direct transmission.
  75. * For a nonbeacon-enabled PAN, bit b1 should always be set to 0.
  76. */
  77. typedef struct
  78. {
  79. uint8_t ack : 1;
  80. uint8_t gts : 1;
  81. uint8_t indirect : 1;
  82. uint8_t : 5;
  83. } mac_tx_options_t;
  84. /**
  85. * @brief MCPS-DATA.confirm.
  86. *
  87. * @details The MCPS-DATA.confirm primitive reports the results of a request to transfer
  88. * a data SPDU (MSDU) from a local SSCS entity to a single peer SSCS entity.
  89. *
  90. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.2.
  91. */
  92. typedef struct
  93. {
  94. /** The handle associated with the MSDU being confirmed. */
  95. uint8_t msdu_handle;
  96. /** The status of the last MSDU transmission. */
  97. mac_status_t status;
  98. /**
  99. * Optional. The time, in symbols, at which the data was transmitted (see 7.5.4.1).
  100. *
  101. * The value of this parameter will be considered valid only if the value of the
  102. * status parameter is SUCCESS; if the status parameter is not equal to
  103. * SUCCESS, the value of the Timestamp parameter will not be used for any other
  104. * purpose. The symbol boundary is described by macSyncSymbolOffset (see Table 86 in 7.4.1).
  105. *
  106. * This is a 24-bit value, and the precision of this value will be a minimum of 20 bits,
  107. * with the lowest 4 bits being the least significant.
  108. */
  109. uint32_t timestamp;
  110. } mcps_data_conf_t;
  111. /**
  112. * @brief MCPS-DATA.request.
  113. *
  114. * @details The MCPS-DATA.request primitive requests the transfer of
  115. * a data SPDU (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity.
  116. *
  117. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.1.
  118. */
  119. typedef struct
  120. {
  121. /** Do not edit this field. */
  122. mac_abstract_req_t service;
  123. /** Confirm to this request. */
  124. mcps_data_conf_t confirm;
  125. /**
  126. * The source addressing mode for this primitive and
  127. * subsequent MPDU. This value can take one of the following values:
  128. * @ref mac_addr_mode_t
  129. * 0x00 = no address (addressing fields omitted, see 7.2.1.1.8).
  130. * 0x01 = reserved.
  131. * 0x02 = 16-bit short address.
  132. * 0x03 = 64-bit extended address.
  133. */
  134. mac_addr_mode_t src_addr_mode;
  135. /**
  136. * The destination addressing mode for this primitive
  137. * and subsequent MPDU.
  138. * According to 7.1.1.1.1, Table 41.
  139. */
  140. mac_addr_mode_t dst_addr_mode;
  141. /** The 16-bit PAN identifier of the entity to which the MSDU is being transferred. */
  142. uint16_t dst_pan_id;
  143. /** The individual device address of the entity to which the MSDU is being transferred. */
  144. mac_addr_t dst_addr;
  145. /** The number of octets contained in the MSDU to be transmitted by
  146. * the MAC sublayer entity.
  147. */
  148. uint8_t msdu_length;
  149. /**
  150. * The pointer to the set of octets forming the MSDU
  151. * to be transmitted by the MAC sublayer entity.
  152. *
  153. * Caller must provide enough space for MAC and PHY header before this pointer.
  154. */
  155. uint8_t * msdu;
  156. /** The handle associated with the MSDU to be transmitted by the MAC sublayer entity. */
  157. uint8_t msdu_handle;
  158. /**
  159. * The bits (b0, b1, b2) indicate the transmission options for this MSDU.
  160. * For b0, 1 = acknowledged transmission, 0 = unacknowledged transmission.
  161. * For b1, 1 = GTS transmission, 0 = CAP transmission for a beacon-enabled PAN.
  162. * For b2, 1 = indirect transmission, 0 = direct transmission.
  163. * For a nonbeacon-enabled PAN, bit b1 should always be set to 0.
  164. */
  165. mac_tx_options_t tx_options;
  166. #if (CONFIG_SECURE == 1)
  167. uint8_t security_level; /**< Security level. */
  168. uint8_t key_id_mode; /**< Key ID node. */
  169. uint64_t key_source; /**< Key source. */
  170. uint8_t key_index; /**< Key index. */
  171. #endif
  172. } mcps_data_req_t;
  173. /**
  174. * @brief Private information passed with MCPS-DATA.indication.
  175. * Not covered by the standard.
  176. */
  177. typedef struct
  178. {
  179. /** RSSI value, which corresponds to packet that caused this indication. */
  180. int8_t rssi;
  181. /** Value of a pending bit from MHR. */
  182. uint8_t pending_bit;
  183. } mcps_data_ind_private_t;
  184. /**
  185. * @brief MCPS-DATA.indication
  186. *
  187. * @details The MCPS-DATA.indication primitive indicates the transfer of
  188. * a data SPDU (i.e., MSDU) from the MAC sublayer to the local SSCS entity.
  189. *
  190. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.3
  191. */
  192. typedef struct
  193. {
  194. mcps_data_ind_private_t service;
  195. /**
  196. * The source addressing mode for this primitive corresponding to the received MPDU.
  197. * According to 7.1.1.1.1, Table 43.
  198. */
  199. mac_addr_mode_t src_addr_mode;
  200. /** The 16-bit PAN identifier of the entity from which the MSDU was received. */
  201. uint16_t src_pan_id;
  202. /** The individual device address of the entity from which the MSDU was received. */
  203. mac_addr_t src_addr;
  204. /**
  205. * The destination addressing mode for this primitive corresponding to the received MPDU.
  206. * According to 7.1.1.1.1, Table 43.
  207. */
  208. mac_addr_mode_t dst_addr_mode;
  209. /** The 16-bit PAN identifier of the entity to which the MSDU is being transferred. */
  210. uint16_t dst_pan_id;
  211. /** The individual device address of the entity to which the MSDU is being transferred. */
  212. mac_addr_t dst_addr;
  213. /** The number of octets contained in the MSDU being indicated by the MAC sublayer entity. */
  214. uint8_t msdu_length;
  215. /**
  216. * The information that is required for the next higher layer to read incoming message and to
  217. * free the memory allocated for this message.
  218. */
  219. mac_payload_descriptor_t msdu;
  220. /**
  221. * LQI value measured during reception of the MPDU.
  222. * Lower values represent lower LQI (see 6.9.8).
  223. */
  224. uint8_t mpdu_link_quality;
  225. /** The DSN of the received data frame. */
  226. uint8_t dsn;
  227. /**
  228. * Optional. The time, in symbols, at which the data was received (see 7.5.4.1).
  229. * The symbol boundary is described by macSyncSymbolOffset (see Table 86 in 7.4.1).
  230. *
  231. * This is a 24-bit value, and the precision of this value shall be a minimum of 20 bits,
  232. * with the lowest 4 bits being the least significant.
  233. */
  234. uint32_t timestamp;
  235. #if (CONFIG_SECURE == 1)
  236. uint8_t security_level; /**< Security level. */
  237. uint8_t key_id_mode; /**< Key ID node. */
  238. uint64_t key_source; /**< Key source. */
  239. uint8_t key_index; /**< Key index. */
  240. #endif
  241. } mcps_data_ind_t;
  242. /**
  243. * @brief Confirmation function.
  244. *
  245. * @details The MCPS-DATA.confirm primitive is generated by the MAC sublayer
  246. * entity in response to an MCPS-DATA. request primitive. The MCPS-DATA.confirm
  247. * primitive returns a status of either SUCCESS, indicating that the request to
  248. * transmit was successful, or the appropriate error code.
  249. * The status values are fully described in 7.1.1.1.3 and subclauses referenced by 7.1.1.1.3.
  250. *
  251. * @param Pointer to confirmation primitive.
  252. */
  253. typedef void (* mcps_data_conf_cb_t)(mcps_data_conf_t *);
  254. /**
  255. * @brief MCPS-DATA.request service
  256. *
  257. * @details The MCPS-DATA.request primitive is generated by a local SSCS entity
  258. * when a data SPDU (i.e., MSDU) is to be transferred to a peer SSCS entity.
  259. * After request completion, user callback will be issued with
  260. * valid data stored in structure @ref mcps_data_conf_t.
  261. *
  262. * @param req Pointer to MCPS-DATA request structure.
  263. * @param conf_cb Pointer to confirmation function (user callback).
  264. *
  265. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.2.
  266. */
  267. void mcps_data_req(mcps_data_req_t * req, mcps_data_conf_cb_t conf_cb);
  268. /**
  269. * @brief MCPS-DATA.indication handler.
  270. *
  271. * @details The MCPS-DATA.indication primitive is generated by the MAC sublayer and
  272. * issued to the SSCS on receipt of a data frame at the local MAC sublayer entity
  273. * that passes the appropriate message filtering operations as described in 7.5.6.2.
  274. *
  275. * @param ind MCPS-DATA.indication structure.
  276. *
  277. * In accordance with IEEE Std 802.15.4-2006, section 7.1.1.3.
  278. */
  279. extern void mcps_data_ind(mcps_data_ind_t * ind);
  280. /**
  281. * @brief Free memory allocated for incoming message.
  282. *
  283. * @details The function will be invoked after all manipulations
  284. * with MSDU are completed. That is necessary to return the memory allocated by MAC
  285. * into the heap.
  286. *
  287. * @param p_payload_descriptor - Pointer to MSDU descriptor.
  288. */
  289. void mac_mem_msdu_free(mac_payload_descriptor_t * p_payload_descriptor);
  290. /** @} */
  291. #endif // MAC_MCPS_DATA_H_INCLUDED