1/********************************************************************* 2 PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights 3 reserved. See LICENSE and COPYING for usage. 4 5 Authors: Jelle De Vleeschouwer 6 *********************************************************************/ 7 8#ifndef INCLUDE_PICO_6LOWPAN_LL 9#define INCLUDE_PICO_6LOWPAN_LL 10 11#include "pico_addressing.h" 12#include "pico_protocol.h" 13#include "pico_6lowpan.h" 14#include "pico_device.h" 15#include "pico_config.h" 16#include "pico_frame.h" 17#include "pico_ipv6.h" 18 19/* Possible actions to perform on a received frame */ 20#define FRAME_6LOWPAN_LL_RELEASE (-1) 21#define FRAME_6LOWPAN_LL_DISCARD (-2) 22 23/******************************************************************************* 24 * CTX 25 ******************************************************************************/ 26 27#ifdef PICO_6LOWPAN_IPHC_ENABLED 28 29#define PICO_IPHC_CTX_COMPRESS (0x01u) 30 31struct iphc_ctx 32{ 33 struct pico_device *dev; 34 struct pico_ip6 prefix; 35 uint8_t id; 36 uint8_t size; 37 uint8_t flags; 38 pico_time lifetime; 39}; 40 41/* 42 * Looks up a context entry for a particular IPv6-address contained in 'addr' and returns it. 43 * Returns NULL if no entry is found. (See RFC4944) 44 */ 45struct iphc_ctx * ctx_lookup(struct pico_ip6 addr); 46 47/* 48 * Looks up a context entry that belongs to a certain context identifier. 49 * Returns NULL if no belonging entry is found. (See RFC4944) 50 */ 51struct iphc_ctx * ctx_lookup_id(uint8_t id); 52 53/* 54 * Creates a new, or updates and existing, context entry for a certain IPv6 address. (See RFC4944) 55 */ 56void ctx_update(struct pico_ip6 addr, uint8_t id, uint8_t size, pico_time lifetime, uint8_t flags, struct pico_device *dev); 57 58#endif 59 60/****************************************************************************** 61 * Interface with device drivers 62 ******************************************************************************/ 63 64struct pico_dev_6lowpan 65{ 66 /* Interface with picoTCP */ 67 struct pico_device dev; 68 69 /* Transmit-function: 70 * 71 * @param dev The device who's send-function got called 72 * @param _buf Buffer containing the frame to be send over the network 73 * @param len Length of _buf 74 * @param src Link Layer source address of the device (IETF-endianness) 75 * @param dst Link layer destination address of the device (IETF-endianness) 76 * 77 * @return length of the frame that is transmitted on success, -1 on failure 78 */ 79 int (* send)(struct pico_device *dev, void *_buf, int len, union pico_ll_addr src, union pico_ll_addr dst); 80}; 81 82/* Initialisation routine for 6LoWPAN specific devices */ 83int pico_dev_6lowpan_init(struct pico_dev_6lowpan *dev, const char *name, uint8_t *mac, enum pico_ll_mode ll_mode, uint16_t mtu, uint8_t nomac, 84 int (* send)(struct pico_device *dev, void *_buf, int len, union pico_ll_addr src, union pico_ll_addr dst), 85 int (* poll)(struct pico_device *dev, int loop_score)); 86 87/****************************************************************************** 88 * Interface with link layer 89 ******************************************************************************/ 90 91struct pico_6lowpan_ll_protocol 92{ 93 int32_t (* process_in)(struct pico_frame *f); 94 int32_t (* process_out)(struct pico_frame *f); 95 int32_t (* estimate)(struct pico_frame *f); 96 int32_t (* addr_from_buf)(union pico_ll_addr *addr, uint8_t *buf); 97 int32_t (* addr_from_net)(union pico_ll_addr *addr, struct pico_frame *f, int32_t dest); 98 int32_t (* addr_len)(union pico_ll_addr *addr); 99 int32_t (* addr_cmp)(union pico_ll_addr *a, union pico_ll_addr *b); 100 int32_t (* addr_iid)(uint8_t *iid, union pico_ll_addr *addr); 101 struct pico_frame * (*alloc)(struct pico_device *dev, uint16_t size); 102}; 103 104/****************************************************************************** 105 * Public variables 106 ******************************************************************************/ 107 108extern struct pico_6lowpan_ll_protocol pico_6lowpan_lls[]; 109extern struct pico_protocol pico_proto_6lowpan_ll; 110 111/****************************************************************************** 112 * Public functions 113 ******************************************************************************/ 114 115void pico_6lowpan_ll_init(void); 116int32_t pico_6lowpan_ll_push(struct pico_frame *f); 117int32_t pico_6lowpan_ll_pull(struct pico_frame *f); 118int32_t frame_6lowpan_ll_store_addr(struct pico_frame *f); 119int32_t pico_6lowpan_ll_sendto_dev(struct pico_device *dev, struct pico_frame *f); 120int32_t pico_6lowpan_stack_recv(struct pico_device *dev, uint8_t *buffer, uint32_t len, union pico_ll_addr *src, union pico_ll_addr *dst); 121 122#endif /* INCLUDE_PICO_6LOWPAN_LL */ 123