sixlowpan_internal.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /****************************************************************************
  2. * net/sixlowpan/sixlowpan_internal.h
  3. *
  4. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Parts of this file derive from Contiki:
  8. *
  9. * Copyright (c) 2008, Swedish Institute of Computer Science
  10. * All rights reserved.
  11. *
  12. * Additional fixes for AVR contributed by:
  13. * Colin O'Flynn coflynn@newae.com
  14. * Eric Gnoske egnoske@gmail.com
  15. * Blake Leverett bleverett@gmail.com
  16. * Mike Vidales mavida404@gmail.com
  17. * Kevin Brown kbrown3@uccs.edu
  18. * Nate Bohlmann nate@elfwerks.com
  19. *
  20. * Additional fixes for MSP430 contributed by:
  21. * Joakim Eriksson
  22. * Niclas Finne
  23. * Nicolas Tsiftes
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or without
  28. * modification, are permitted provided that the following conditions are met:
  29. *
  30. * 1. Redistributions of source code must retain the above copyright
  31. * notice, this list of conditions and the following disclaimer.
  32. * 2. Redistributions in binary form must reproduce the above copyright
  33. * notice, this list of conditions and the following disclaimer in
  34. * the documentation and/or other materials provided with the
  35. * distribution.
  36. * 3. Neither the name of the copyright holders nor the names of
  37. * contributors may be used to endorse or promote products derived
  38. * from this software without specific prior written permission.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  41. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  44. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  45. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  50. * POSSIBILITY OF SUCH DAMAGE.
  51. ****************************************************************************/
  52. #ifndef _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H
  53. #define _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H
  54. /****************************************************************************
  55. * Included Files
  56. ****************************************************************************/
  57. #include <nuttx/config.h>
  58. #include <sys/types.h>
  59. #include <stdbool.h>
  60. #include <nuttx/net/tcp.h>
  61. #include <nuttx/net/udp.h>
  62. #include <nuttx/net/icmpv6.h>
  63. #include <nuttx/net/sixlowpan.h>
  64. #include <nuttx/wireless/pktradio.h>
  65. #ifdef CONFIG_NET_6LOWPAN
  66. /****************************************************************************
  67. * Pre-processor Definitions
  68. ****************************************************************************/
  69. /* Copy a generic address */
  70. #define sixlowpan_anyaddrcopy(dest,src,len) \
  71. memcpy(dest, src, len)
  72. #ifdef CONFIG_WIRELESS_IEEE802154
  73. /* IEEE 802.15.4 address macros */
  74. /* Copy a an IEEE 802.15.4 address */
  75. #define sixlowpan_saddrcopy(dest,src) \
  76. sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_SADDRSIZE)
  77. #define sixlowpan_eaddrcopy(dest,src) \
  78. sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_EADDRSIZE)
  79. #define sixlowpan_addrcopy(dest,src) \
  80. sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_ADDRSIZE)
  81. #endif
  82. /* General helper macros ****************************************************/
  83. /* GET 16-bit data: source in network order */
  84. #define GETUINT16(ptr,index) \
  85. ((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1]))))
  86. /* PUT 16-bit data: source in host order, result in network order */
  87. #define PUTHOST16(ptr,index,value) \
  88. do \
  89. { \
  90. (ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \
  91. (ptr)[index + 1] = (uint16_t)(value) & 0xff; \
  92. } \
  93. while (0)
  94. /* Return values ************************************************************/
  95. /* Successful return values from header compression logic */
  96. #define COMPRESS_HDR_INLINE 0 /* L2 header not compressed */
  97. #define COMPRESS_HDR_ELIDED 1 /* L2 header compressed */
  98. /* Memory Pools *************************************************************/
  99. #define REASS_POOL_PREALLOCATED 0
  100. #define REASS_POOL_DYNAMIC 1
  101. #define REASS_POOL_RADIO 2
  102. /* Debug ********************************************************************/
  103. #ifdef CONFIG_NET_6LOWPAN_DUMPBUFFER
  104. # define sixlowpan_dumpbuffer(m,b,s) ninfodumpbuffer(m,b,s)
  105. #else
  106. # define sixlowpan_dumpbuffer(m,b,s)
  107. #endif
  108. /****************************************************************************
  109. * Public Types
  110. ****************************************************************************/
  111. /* IPv6 TCP/UDP/ICMPv6 Definitions ******************************************/
  112. #ifdef CONFIG_NET_TCP
  113. /* IPv6 + TCP header. Cast compatible based on IPv6 protocol field. */
  114. struct ipv6tcp_hdr_s
  115. {
  116. struct ipv6_hdr_s ipv6;
  117. struct tcp_hdr_s tcp;
  118. };
  119. #endif
  120. #ifdef CONFIG_NET_UDP
  121. /* IPv6 + UDP header */
  122. struct ipv6udp_hdr_s
  123. {
  124. struct ipv6_hdr_s ipv6;
  125. struct udp_hdr_s udp;
  126. };
  127. #endif
  128. #ifdef CONFIG_NET_ICMPv6
  129. /* IPv6 + ICMPv6 header */
  130. struct ipv6icmp_hdr_s
  131. {
  132. struct ipv6_hdr_s ipv6;
  133. struct icmpv6_iphdr_s icmp;
  134. };
  135. #endif
  136. #ifdef CONFIG_WIRELESS_IEEE802154
  137. /* In order to provide a customizable IEEE 802.15.4 MAC header, a structure
  138. * of meta data is passed to the MAC network driver, struct
  139. * ieee802154_frame_meta_s. Many of the settings in this meta data are
  140. * fixed, determined by the 6LoWPAN configuration. Other settings depend
  141. * on the protocol used in the current packet or on chacteristics of the
  142. * destination node.
  143. *
  144. * The following structure is used to summarize those per-packet
  145. * customizations and, along, with the fixed configuratoin settings,
  146. * determines the full form of that meta data.
  147. */
  148. struct ieee802_txmetadata_s
  149. {
  150. uint8_t sextended : 1; /* Extended source address */
  151. uint8_t dextended : 1; /* Extended destination address */
  152. uint8_t xmits; /* Max MAC transmisstion */
  153. uint8_t dpanid[IEEE802154_PANIDSIZE]; /* Destination PAN ID */
  154. struct netdev_maxaddr_s source; /* Source IEEE 802.15.4 address */
  155. struct netdev_maxaddr_s dest; /* Destination IEEE 802.15.4 address */
  156. };
  157. #endif
  158. /* This structure holds the packet metadata as a union when multiple different
  159. * radio type are supported.
  160. */
  161. union sixlowpan_metadata_u
  162. {
  163. #ifdef CONFIG_WIRELESS_IEEE802154
  164. struct ieee802154_frame_meta_s ieee802154;
  165. #endif
  166. #ifdef CONFIG_WIRELESS_PKTRADIO
  167. struct pktradio_metadata_s pktradio;
  168. #endif
  169. };
  170. /****************************************************************************
  171. * Public Data
  172. ****************************************************************************/
  173. /* The following data values are used to hold intermediate settings while
  174. * processing IEEE802.15.4 frames. These globals are shared with incoming
  175. * and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC
  176. * devices. The network lock provides exclusive use of these globals
  177. * during that processing
  178. */
  179. /* g_uncomp_hdrlen is the length of the headers before compression (if HC2
  180. * is used this includes the UDP header in addition to the IP header).
  181. */
  182. extern uint8_t g_uncomp_hdrlen;
  183. /* g_frame_hdrlen is the total length of (the processed) 6lowpan headers
  184. * (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
  185. * fields).
  186. */
  187. extern uint8_t g_frame_hdrlen;
  188. /****************************************************************************
  189. * Public Types
  190. ****************************************************************************/
  191. /****************************************************************************
  192. * Public Function Prototypes
  193. ****************************************************************************/
  194. struct net_driver_s; /* Forward reference */
  195. struct radio_driver_s; /* Forward reference */
  196. struct devif_callback_s; /* Forward reference */
  197. struct ipv6_hdr_s; /* Forward reference */
  198. struct netdev_varaddr_s; /* Forward reference */
  199. struct iob_s; /* Forward reference */
  200. /****************************************************************************
  201. * Name: sixlowpan_send
  202. *
  203. * Description:
  204. * Process an outgoing UDP or ICMPv6 packet. Takes an IP packet and formats
  205. * it to be sent on an 802.15.4 network using 6lowpan. Called from common
  206. * UDP/ICMPv6 send logic.
  207. *
  208. * The payload data is in the caller 'buf' and is of length 'buflen'.
  209. * Compressed headers will be added and if necessary the packet is
  210. * fragmented. The resulting packet/fragments are submitted to the MAC
  211. * via the network driver r_req_data method.
  212. *
  213. * Input Parameters:
  214. * dev - The IEEE802.15.4 MAC network driver interface.
  215. * list - Head of callback list for send event handler
  216. * ipv6hdr - IPv6 header followed by UDP or ICMPv6 header.
  217. * buf - Data to send
  218. * len - Length of data to send
  219. * destmac - The IEEE802.15.4 MAC address of the destination
  220. * timeout - Send timeout in deciseconds
  221. *
  222. * Returned Value:
  223. * Ok is returned on success; Othewise a negated errno value is returned.
  224. * This function is expected to fail if the driver is not an IEEE802.15.4
  225. * MAC network driver. In that case, the logic will fall back to normal
  226. * IPv4/IPv6 formatting.
  227. *
  228. * Assumptions:
  229. * Called with the network locked.
  230. *
  231. ****************************************************************************/
  232. int sixlowpan_send(FAR struct net_driver_s *dev,
  233. FAR struct devif_callback_s **list,
  234. FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf,
  235. size_t len, FAR const struct netdev_varaddr_s *destmac,
  236. uint16_t timeout);
  237. /****************************************************************************
  238. * Name: sixlowpan_meta_data
  239. *
  240. * Description:
  241. * Based on the collected attributes and addresses, construct the MAC meta
  242. * data structure that we need to interface with the IEEE802.15.4 MAC.
  243. *
  244. * Input Parameters:
  245. * radio - Reference to a radio network driver state instance.
  246. * pktmeta - Meta-data specific to the current outgoing frame
  247. * meta - Location to return the corresponding meta data reference
  248. * (obfuscated).
  249. *
  250. * Returned Value:
  251. * Ok is returned on success; Othewise a negated errno value is returned.
  252. *
  253. * Assumptions:
  254. * Called with the network locked.
  255. *
  256. ****************************************************************************/
  257. #ifdef CONFIG_WIRELESS_IEEE802154
  258. int sixlowpan_meta_data(FAR struct radio_driver_s *radio,
  259. FAR const struct ieee802_txmetadata_s *pktmeta,
  260. FAR struct ieee802154_frame_meta_s *meta);
  261. #endif
  262. /****************************************************************************
  263. * Name: sixlowpan_frame_hdrlen
  264. *
  265. * Description:
  266. * This function is before the first frame has been sent in order to
  267. * determine what the size of the IEEE802.15.4 header will be. No frame
  268. * buffer is required to make this determination.
  269. *
  270. * Input Parameters:
  271. * radio - Reference to a radio network driver state instance.
  272. * meta - obfuscated meta data that describes the MAC header
  273. *
  274. * Returned Value:
  275. * The frame header length is returnd on success; otherwise, a negated
  276. * errno value is return on failure.
  277. *
  278. ****************************************************************************/
  279. int sixlowpan_frame_hdrlen(FAR struct radio_driver_s *radio,
  280. FAR const void *meta);
  281. /****************************************************************************
  282. * Name: sixlowpan_frame_submit
  283. *
  284. * Description:
  285. * This function is called after eiether (1) the IEEE802.15.4 MAC driver
  286. * polls for TX data or (2) after the IEEE802.15.4 MAC driver provides a
  287. * new incoming frame and the network responds with an outgoing packet. It
  288. * submits any new outgoing frame to the MAC.
  289. *
  290. * Input Parameters:
  291. * radio - Reference to a radio network driver state instance.
  292. * meta - Obfuscated metadata that describes the MAC header
  293. * frame - The IOB containing the frame to be submitted.
  294. *
  295. * Returned Value:
  296. * Zero (OK) is returned on success; otherwise, a negated errno value is
  297. * return on any failure.
  298. *
  299. ****************************************************************************/
  300. int sixlowpan_frame_submit(FAR struct radio_driver_s *radio,
  301. FAR const void *meta, FAR struct iob_s *frame);
  302. /****************************************************************************
  303. * Name: sixlowpan_queue_frames
  304. *
  305. * Description:
  306. * Process an outgoing UDP or TCP packet. This function is called from
  307. * the send event handler when a TX poll is received. It formates the
  308. * list of frames to be sent by the IEEE802.15.4 MAC driver.
  309. *
  310. * The payload data is in the caller 'buf' and is of length 'buflen'.
  311. * Compressed headers will be added and if necessary the packet is
  312. * fragmented. The resulting packet/fragments are submitted to the MAC
  313. * via the network driver r_req_data method.
  314. *
  315. * Input Parameters:
  316. * radio - Reference to a radio network driver state instance.
  317. * ipv6 - IPv6 header followed by TCP or UDP header.
  318. * buf - Beginning of the packet packet to send (with IPv6 + protocol
  319. * headers)
  320. * buflen - Length of data to send (includes IPv6 and protocol headers)
  321. * destmac - The IEEE802.15.4 MAC address of the destination
  322. *
  323. * Returned Value:
  324. * Ok is returned on success; Othewise a negated errno value is returned.
  325. * This function is expected to fail if the driver is not an IEEE802.15.4
  326. * MAC network driver. In that case, the UDP/TCP will fall back to normal
  327. * IPv4/IPv6 formatting.
  328. *
  329. * Assumptions:
  330. * Called with the network locked.
  331. *
  332. ****************************************************************************/
  333. int sixlowpan_queue_frames(FAR struct radio_driver_s *radio,
  334. FAR const struct ipv6_hdr_s *ipv6,
  335. FAR const void *buf, size_t buflen,
  336. FAR const struct netdev_varaddr_s *destmac);
  337. /****************************************************************************
  338. * Name: sixlowpan_hc06_initialize
  339. *
  340. * Description:
  341. * sixlowpan_hc06_initialize() is called during OS initialization at power-up
  342. * reset. It is called from the common sixlowpan_initialize() function.
  343. * sixlowpan_hc06_initialize() configures HC06 networking data structures.
  344. * It is called prior to platform-specific driver initialization so that
  345. * the 6LoWPAN networking subsystem is prepared to deal with network
  346. * driver initialization actions.
  347. *
  348. * Input Parameters:
  349. * None
  350. *
  351. * Returned Value:
  352. * None
  353. *
  354. ****************************************************************************/
  355. #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
  356. void sixlowpan_hc06_initialize(void);
  357. #endif
  358. /****************************************************************************
  359. * Name: sixlowpan_compresshdr_hc06
  360. *
  361. * Description:
  362. * Compress IP/UDP header
  363. *
  364. * This function is called by the 6lowpan code to create a compressed
  365. * 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
  366. * uip_buf buffer.
  367. *
  368. * HC-06:
  369. *
  370. * Originally draft-ietf-6lowpan-hc, version 6:
  371. * http://tools.ietf.org/html/draft-ietf-6lowpan-hc-06,
  372. *
  373. * Updated to:
  374. *
  375. * RFC 6282:
  376. * https://tools.ietf.org/html/rfc6282
  377. *
  378. * NOTE: sixlowpan_compresshdr_hc06() does not support ISA100_UDP header
  379. * compression
  380. *
  381. * Input Parameters:
  382. * radio - Reference to a radio network driver state instance.
  383. * ipv6 - The IPv6 header to be compressed
  384. * destmac - L2 destination address, needed to compress the IP
  385. * destination field
  386. * fptr - Pointer to frame to be compressed.
  387. *
  388. * Returned Value:
  389. * On success the indications of the defines COMPRESS_HDR_* are returned.
  390. * A negated errno value is returned on failure.
  391. *
  392. ****************************************************************************/
  393. #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
  394. int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio,
  395. FAR const struct ipv6_hdr_s *ipv6,
  396. FAR const struct netdev_varaddr_s *destmac,
  397. FAR uint8_t *fptr);
  398. #endif
  399. /****************************************************************************
  400. * Name: sixlowpan_uncompresshdr_hc06
  401. *
  402. * Description:
  403. * Uncompress HC06 (i.e., IPHC and LOWPAN_UDP) headers and put them in
  404. * sixlowpan_buf
  405. *
  406. * This function is called by the input function when the dispatch is HC06.
  407. * We process the frame in the IOB buffer, uncompress the header fields,
  408. * and copy the result into the driver packet buffer. At the end of the
  409. * decompression, g_frame_hdrlen and g_uncompressed_hdrlen are set to the
  410. * appropriate values
  411. *
  412. * Input Parameters:
  413. * radio - Reference to a radio network driver state instance.
  414. * metadata - Obfuscated MAC metadata including node addressing
  415. * information.
  416. * iplen - Equal to 0 if the packet is not a fragment (IP length is
  417. * then inferred from the L2 length), non 0 if the packet is
  418. * a first fragment.
  419. * iob - Pointer to the IOB containing the received frame.
  420. * fptr - Pointer to frame to be compressed.
  421. * bptr - Output goes here. Normally this is a known offset into
  422. * d_buf, may be redirected to a "bitbucket" on the case of
  423. * FRAGN frames.
  424. *
  425. * Returned Value:
  426. * None
  427. *
  428. ****************************************************************************/
  429. #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
  430. void sixlowpan_uncompresshdr_hc06(FAR struct radio_driver_s *radio,
  431. FAR const void *metadata,
  432. uint16_t iplen, FAR struct iob_s *iob,
  433. FAR uint8_t *fptr, FAR uint8_t *bptr);
  434. #endif
  435. /****************************************************************************
  436. * Name: sixlowpan_compresshdr_hc1
  437. *
  438. * Description:
  439. * Compress IP/UDP header using HC1 and HC_UDP
  440. *
  441. * This function is called by the 6lowpan code to create a compressed
  442. * 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
  443. * uip_buf buffer.
  444. *
  445. * Input Parameters:
  446. * radio - Reference to a radio network driver state instance.
  447. * ipv6 - The IPv6 header to be compressed
  448. * destmac - L2 destination address, needed to compress the IP
  449. * destination field
  450. * fptr - Pointer to frame to be compressed.
  451. *
  452. * Returned Value:
  453. * On success the indications of the defines COMPRESS_HDR_* are returned.
  454. * A negated errno value is returned on failure.
  455. *
  456. ****************************************************************************/
  457. #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
  458. int sixlowpan_compresshdr_hc1(FAR struct radio_driver_s *radio,
  459. FAR const struct ipv6_hdr_s *ipv6,
  460. FAR const struct netdev_varaddr_s *destmac,
  461. FAR uint8_t *fptr);
  462. #endif
  463. /****************************************************************************
  464. * Name: sixlowpan_uncompresshdr_hc1
  465. *
  466. * Description:
  467. * Uncompress HC1 (and HC_UDP) headers and put them in sixlowpan_buf
  468. *
  469. * This function is called by the input function when the dispatch is
  470. * HC1. It processes the frame in the IOB buffer, uncompresses the
  471. * header fields, and copies the result in the packet buffer. At the
  472. * end of the decompression, g_frame_hdrlen and uncompressed_hdr_len
  473. * are set to the appropriate values
  474. *
  475. * Input Parameters:
  476. * radio - Reference to a radio network driver state instance.
  477. * metadata - Obfuscated MAC metadata including node addressing
  478. * information.
  479. * iplen - Equal to 0 if the packet is not a fragment (IP length is
  480. * then inferred from the L2 length), non 0 if the packet is
  481. * a 1st fragment.
  482. * iob - Pointer to the IOB containing the received frame.
  483. * fptr - Pointer to frame to be uncompressed.
  484. * bptr - Output goes here. Normally this is a known offset into
  485. * d_buf, may be redirected to a "bitbucket" on the case of
  486. * FRAGN frames.
  487. *
  488. * Returned Value:
  489. * Zero (OK) is returned on success, on failure a negated errno value is
  490. * returned.
  491. *
  492. ****************************************************************************/
  493. #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
  494. int sixlowpan_uncompresshdr_hc1(FAR struct radio_driver_s *radio,
  495. FAR const void *metadata, uint16_t iplen,
  496. FAR struct iob_s *iob, FAR uint8_t *fptr,
  497. FAR uint8_t *bptr);
  498. #endif
  499. /****************************************************************************
  500. * Name: sixlowpan_nexthopaddr
  501. *
  502. * Description:
  503. * sixlowpan_nexthopaddr(): If the destination is on-link, extract the
  504. * IEEE 802.15.14 destination address from the destination IP address. If the
  505. * destination is not reachable directly, use the routing table (if available)
  506. * or fall back to the default router IP address and use the router IP address
  507. * to derive the IEEE 802.15.4 MAC address.
  508. *
  509. ****************************************************************************/
  510. int sixlowpan_nexthopaddr(FAR struct radio_driver_s *radio,
  511. FAR const net_ipv6addr_t ipaddr,
  512. FAR struct netdev_varaddr_s *destaddr);
  513. /****************************************************************************
  514. * Name: sixlowpan_islinklocal, sixlowpan_destaddrfromip, and
  515. * sixlowpan_ismacbased
  516. *
  517. * Description:
  518. * sixlowpan_destaddrfromip(): Extract the IEEE 802.15.14 destination
  519. * address from a MAC-based destination IPv6 address. This function
  520. * handles a tagged address union which may either a short or and
  521. * extended destination address.
  522. *
  523. * In the case there the IEEE 802.15.4 node functions as an endpoint in a
  524. * start topology, the destination address will, instead, be the address
  525. * of the star hub (which is assumed to be the address of the cooordinator).
  526. *
  527. * sixlowpan_ipfrom[s|e]addr(): Create a link-local, MAC-based IPv6
  528. * address from an IEEE802.15.4 short address (saddr) or extended address
  529. * (eaddr).
  530. *
  531. * sixlowpan_islinklocal() and sixlowpan_ismacbased() will return true for
  532. * address created in this fashion. sixlowpan_destaddrfromip() is intended to
  533. * handle a tagged address or any size. Local addresses are of a fixed but
  534. * configurable size and sixlowpan_isaddrbased() is for use with such local
  535. * addresses.
  536. *
  537. * 128 112 96 80 64 48 32 16
  538. * ---- ---- ---- ---- ---- ---- ---- ----
  539. * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC
  540. * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64
  541. *
  542. ****************************************************************************/
  543. #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80))
  544. int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio,
  545. const net_ipv6addr_t ipaddr,
  546. FAR struct netdev_varaddr_s *addr);
  547. void sixlowpan_ipfromaddr(FAR const struct netdev_varaddr_s *addr,
  548. FAR net_ipv6addr_t ipaddr);
  549. bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
  550. FAR const struct netdev_varaddr_s *addr);
  551. /****************************************************************************
  552. * Name: sixlowpan_radio_framelen
  553. *
  554. * Description:
  555. * Get the maximum frame length supported by radio network drvier.
  556. *
  557. * Input Parameters:
  558. * radio - Reference to a radio network driver state instance.
  559. *
  560. * Returned Value:
  561. * A non-negative, maximum frame lengthis returned on success; A negated
  562. * errno valueis returned on any failure.
  563. *
  564. ****************************************************************************/
  565. int sixlowpan_radio_framelen(FAR struct radio_driver_s *radio);
  566. /****************************************************************************
  567. * Name: sixlowpan_src_panid
  568. *
  569. * Description:
  570. * Get the source PAN ID from the IEEE802.15.4 radio.
  571. *
  572. * Input Parameters:
  573. * radio - Reference to a radio network driver state instance.
  574. * panid - The location in which to return the PAN ID. 0xfff may be
  575. * returned if the device is not associated.
  576. *
  577. * Returned Value:
  578. * Zero (OK) on success; a negated errno value on failure.
  579. *
  580. ****************************************************************************/
  581. #ifdef CONFIG_WIRELESS_IEEE802154
  582. int sixlowpan_src_panid(FAR struct radio_driver_s *radio,
  583. FAR uint8_t *panid);
  584. #endif
  585. /****************************************************************************
  586. * Name: sixlowpan_extract_srcaddr
  587. *
  588. * Description:
  589. * Extract the source MAC address from the radio-specific RX metadata, and
  590. * return the source address in a radio-agnostic form.
  591. *
  592. * Input Parameters:
  593. * radio - Reference to a radio network driver state instance.
  594. * metadata - Opaque reference to the radio-specific RX metadata.
  595. * srcaddr - The location in which to return the source MAC address.
  596. *
  597. * Returned Value:
  598. * Zero (OK) on success; a negated errno value on failure.
  599. *
  600. ****************************************************************************/
  601. int sixlowpan_extract_srcaddr(FAR struct radio_driver_s *radio,
  602. FAR const void *metadata,
  603. FAR struct netdev_varaddr_s *srcaddr);
  604. /****************************************************************************
  605. * Name: sixlowpan_extract_destaddr
  606. *
  607. * Description:
  608. * Extract the destination MAC address from the radio-specific RX metadata,
  609. * and return the destination address in a radio-agnostic form.
  610. *
  611. * Input Parameters:
  612. * radio - Reference to a radio network driver state instance.
  613. * metadata - Opaque reference to the radio-specific RX metadata.
  614. * destaddr - The location in which to return the destination MAC address.
  615. *
  616. * Returned Value:
  617. * Zero (OK) on success; a negated errno value on failure.
  618. *
  619. ****************************************************************************/
  620. int sixlowpan_extract_destaddr(FAR struct radio_driver_s *radio,
  621. FAR const void *metadata,
  622. FAR struct netdev_varaddr_s *destaddr);
  623. /****************************************************************************
  624. * Name: sixlowpan_reass_initialize
  625. *
  626. * Description:
  627. * This function initializes the reassembly buffer allocator. This
  628. * function must be called early in the initialization sequence before
  629. * any radios begin operation.
  630. *
  631. * Called only once during network initialization.
  632. *
  633. * Input Parameters:
  634. * None
  635. *
  636. * Returned Value:
  637. * None
  638. *
  639. ****************************************************************************/
  640. void sixlowpan_reass_initialize(void);
  641. /****************************************************************************
  642. * Name: sixlowpan_reass_allocate
  643. *
  644. * Description:
  645. * The sixlowpan_reass_allocate function will get a free reassembly buffer
  646. * structure for use by 6LoWPAN.
  647. *
  648. * This function will first attempt to allocate from the g_free_reass
  649. * list. If that the list is empty, then the reassembly buffer structure
  650. * will be allocated from the dynamic memory pool.
  651. *
  652. * Input Parameters:
  653. * reasstag - The reassembly tag for subsequent lookup.
  654. * fragsrc - The source address of the fragment.
  655. *
  656. * Returned Value:
  657. * A reference to the allocated reass structure. All fields used by the
  658. * reasembly logic have been zeroed. On a failure to allocate, NULL is
  659. * returned.
  660. *
  661. * Assumptions:
  662. * The network is locked.
  663. *
  664. ****************************************************************************/
  665. FAR struct sixlowpan_reassbuf_s *
  666. sixlowpan_reass_allocate(uint16_t reasstag,
  667. FAR const struct netdev_varaddr_s *fragsrc);
  668. /****************************************************************************
  669. * Name: sixlowpan_reass_find
  670. *
  671. * Description:
  672. * Find a previously allocated, active reassembly buffer with the specified
  673. * reassembly tag.
  674. *
  675. * Input Parameters:
  676. * reasstag - The reassembly tag to match.
  677. * fragsrc - The source address of the fragment.
  678. *
  679. * Returned Value:
  680. * A reference to the matching reass structure.
  681. *
  682. * Assumptions:
  683. * The network is locked.
  684. *
  685. ****************************************************************************/
  686. FAR struct sixlowpan_reassbuf_s *
  687. sixlowpan_reass_find(uint16_t reasstag,
  688. FAR const struct netdev_varaddr_s *fragsrc);
  689. /****************************************************************************
  690. * Name: sixlowpan_reass_free
  691. *
  692. * Description:
  693. * The sixlowpan_reass_free function will return a reass structure
  694. * to the free list of messages if it was a pre-allocated reass
  695. * structure. If the reass structure was allocated dynamically it will
  696. * be deallocated.
  697. *
  698. * Input Parameters:
  699. * reass - reass structure to free
  700. *
  701. * Returned Value:
  702. * None
  703. *
  704. * Assumptions:
  705. * The network is locked.
  706. *
  707. ****************************************************************************/
  708. void sixlowpan_reass_free(FAR struct sixlowpan_reassbuf_s *reass);
  709. #endif /* CONFIG_NET_6LOWPAN */
  710. #endif /* _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H */