Data Structures | |
struct | fip_packet_t |
Hold the current active packet. More... | |
Modules | |
IPv6 Specific Packet Handling | |
ICMPv6 Specific Packet Handling | |
Files | |
file | fip_packet.c |
Active Packet Interface. | |
Defines | |
#define | fip_packet_getFromIP6Hdr_isSrcMulticast() (*(fip_packet_getIPBufPtr() + 8) == 0xFF) |
Optimised function to check for IPv6 Multicast in source address. | |
#define | fip_packet_getFromIP6Hdr_isDestMulticast() (*(fip_packet_getIPBufPtr() + 24) == 0xFF) |
Optimized function to check for IPv6 Multicast in dest address. | |
#define | fip_packet_getFromIP6Hdr_isDestLinkLocal() (*(fip_packet_getIPBufPtr() + 24) == 0xFE) |
#define | fip_packet_getBufPtr(bufNum) (fip_packet_get().buf[bufNum].ptr) |
Get a pointer to a specific buffer, such as the L2 buffer, IP buffer, etc. | |
#define | fip_packet_getBufMaxSize(bufNum) (fip_packet_get().buf[bufNum].allocSize) |
Get the allocated (maximum) size of a buffer. | |
#define | fip_packet_getBufSize(bufNum) (fip_packet_get().buf[bufNum].usedSize) |
Get the size of data currently written into the buffer. | |
#define | fip_packet_setBufSize(bufNum, size) (fip_packet_get().buf[bufNum].usedSize = size) |
Set the size of data currently written into the buffer. | |
#define | fip_packet_getAttr(attr) fip_packet_get().attr |
Get the value of an attribute from the active packet buffer. | |
#define | fip_packet_setAttr(attr, value) fip_packet_get().attr = (value) |
Set the value of an attribute to the active packet buffer. | |
#define | fip_packet_setLLSrcAddr(addr, len) |
Set the LL source address, you must have set the srcLLAddrOffset attribute before calling this! | |
#define | fip_packet_setLLDestAddr(addr, len) |
Set the LL dest address, you must have set the destLLAddrOffset attribute before calling this! | |
#define | fip_packet_setAddrFlags(type, flag, value) (fip_packet_get().type.flag = value) |
Set the address flags. | |
#define | fip_packet_getAddrFlags(type, flag) fip_packet_get().type.flag |
Get the address flags. | |
#define | fip_packet_spGetPtr(type) ((type *)(fip_packet_get().scratchPad)) |
Get a pointer to the 'scratchpad', and cast it to a pointer of the type passed. | |
#define | fip_packet_getFromBuf_Uint8Unaligned(offset, bufNum) |
#define | fip_packet_getIfNum() fip_packet_getAttr(IFNum) |
Get the interface number, available as a separate macro as single-interface systems can replace this with a constant. | |
Enumerations | |
enum | fip_packetstate_t { PS_UNUSED, PS_EMPTY, PS_RECEIVINGLL, PS_PROCESSIP, PS_WAITING_AR, PS_SEND, PS_IPFRAG, PS_STARTLLSEND, PS_LLSENDING } |
Valid states the active packet buffer can be in. More... | |
Functions | |
fip_return_t | fip_packet_activeNew (fip_bufnum_t bufnum, uint16_t length, fip_ifnum_t ifnum) |
Allocate a new packet & make active. | |
fip_return_t | fip_packet_ptrBufCpyFromActive (fip_packet_t *packetPtr, unsigned int destOffset, uint8_t *srcData, unsigned int dataLen) |
Copy srcLen bytes from srcData to the FIP_IPHDRBUF of fragLocation offset from the start, extending the buffer if required to fit the data in. | |
fip_return_t | fip_packet_activeUnqueuePacket (void) |
If current packet is PS_UNUSED, swap it with something else. | |
void | fip_packet_activeQueuePacket (void) |
Push the active packet into the queue if supported, if not supported this just frees the packet. | |
void | fip_packet_activeDrop (void) |
Deallocate the active packet. | |
fip_return_t | fip_packet_activeResponsePacket (fip_bufnum_t bufnum, unsigned int length) |
Deallocate the current buffer, and allocate a new buffer. | |
void | fip_packet_activeBufSplit (fip_bufnum_t original, fip_bufnum_t new) |
Takes the specified origin buffer, and splits off all the free space (between allocSize and Size) and moves it to the new buffer, before using this function be SURE allocSize is set correctly in the 'original' buffer, and you don't have free space at the end. | |
unsigned int | fip_packet_getBufSizes (fip_bufnum_t first, fip_bufnum_t last) |
Returns the total size of all buffers specified, starting at 'first' up to but NOT INCLUDING 'last'. | |
void | fip_packet_copyToIP6Hdr_destAddr (const uint8_t *const address) |
Copies 16 bytes from the pointer to the IPv6 Destination Address and resets all associated flags containing attributes about the address. | |
void | fip_packet_copyToIP6Hdr_srcAddr (const uint8_t *const address) |
Copies 16 bytes from the pointer to the IPv6 Source Address and resets all associated flags containing attributes about the address . | |
void | fip_packet_setToIP6Hdr_srcAddrUnspecified (void) |
Sets the IPv6 Source Address as the Unspecified Address. | |
void | fip_packet_setToIP6Hdr_destAddrAllNodes (void) |
Sets the IPv6 Destination Address as the All Nodes Address. | |
void | fip_packet_setToIP6Hdr_destAddrAllRouters (void) |
Sets the IPv6 Destination Address as the All Routers Address. | |
Variables | |
uint8_t | fip_activePacket_buffer [FIP_STATIC_BUF_SIZE] |
NB: There are two methods allowed to access the global fip_activePacket structure and directory. |
The active packet could contain a number of different buffers to store information such as Link-Layer Headers, IP Headers, IP Data, UDP Data, etc. The buffers are flexible themselves in that they can be just be statically or dynamically allocated depending on your available resources.
The configuration file will define possible buffers you can use. They must be configured as a number indicating the order in which the packets will be sent, although adding data can occur in any order. Thus you can fill in buffer 0, 3, 2, 4 in that order. When the packet is sent the message will look like [0][2][3][4]. Note buffer 1 had nothing in it, so was omitted from the final message. This configuration allows you to for example define IPv6 Extension Header buffers, and when you need to insert one there is no need to actually move anything, you just insert a pointer to where the extension header is stored.
An example configuration file might look like:
//Link-layer Buffer #define FIP_LLBUF 0 //IPv6 Header Buffer #define FIP_IPHDRBUF 1 //IPv6 Hop-By-Hop Buffer #define FIP_IPHBHBUF 2 //IPv6 Routing Header Buffer #define FIP_IPRHBUF 3 //IPv6 Additional Header Space #define FIP_IPAHBUF 4 //Transport Layer Buffer #define FIP_TLBUF 5 //Application Layer Buffer #define FIP_APPBUF 6 //Total of 7 buffer types defined (0-6) #define FIP_NUMBUFS 7
You don't need to use every buffer type you define, but you can't use any type more than once on any packet. If you required multiple of the same type (e.g. for tunnelling, multiple extension headers) you need to define things like FIP_IPHBH1, etc. Each buffer has the following properties:
Ptr
A pointer to the bufferAllocSize
The allocated size of the bufferUsedSize
The actual space used in the buffer
srcLLAddrOffset
Offset of the source LL Address from start of LL buffersrcLLAddrLen
Length of the source LL address in bytesdestLLAddrOffset
Offset of the destination LL Address from start of LL bufferdestLLAddrLen
Length of the destination LL address in bytes#define fip_packet_getAddrFlags | ( | type, | |||
flag | ) | fip_packet_get().type.flag |
Get the address flags.
type | Either 'srcFlags' or 'destFlags' | |
flag | See fip_ip6addr_flags_t for flags |
Referenced by fip_isDestUnspecified(), fip_isSrcUnspecified(), and fip_nd6_processNS().
#define fip_packet_getAttr | ( | attr | ) | fip_packet_get().attr |
Get the value of an attribute from the active packet buffer.
attr | The attribute to get. Valid values are elements of the fip_packet_t struct. |
Referenced by fip_console(), fip_if6_isDestMyMulticast(), fip_if6_selectSrcAddress(), fip_if6_shortenLLAOLength(), fip_if_newPacketSetup(), fip_ip_process(), fip_ip_send(), fip_nd6_processNS(), fip_packet_activeNew(), fip_packet_activeResponsePacket(), fip_packet_activeUnqueuePacket(), fip_route6_getNextHop(), fip_sixlowpan_llInput(), fip_sixlowpan_process(), and fip_task().
#define fip_packet_getBufMaxSize | ( | bufNum | ) | (fip_packet_get().buf[bufNum].allocSize) |
Get the allocated (maximum) size of a buffer.
bufNum | Buffer to get the max size of |
Referenced by fip_if_newPacketSetup(), fip_ip_process(), and fip_packet_activeBufSplit().
#define fip_packet_getBufPtr | ( | bufNum | ) | (fip_packet_get().buf[bufNum].ptr) |
Get a pointer to a specific buffer, such as the L2 buffer, IP buffer, etc.
bufNum | Buffer to get a pointer to |
Referenced by fip_icmp6_generateEchoRequest(), fip_icmp6_generateError(), fip_icmp6_process(), fip_ip_process(), fip_ipUtils_checksum_tl(), fip_nd6_6lowpan_addRAOptions(), fip_nd6_6lowpan_processNA(), fip_nd6_addLLAO(), fip_nd6_generateNA(), fip_nd6_generateNS(), fip_nd6_generateRA(), fip_nd6_generateRS(), fip_nd6_processLLAO(), fip_nd6_processNA(), fip_nd6_processNS(), fip_nd6_processRA(), fip_nd6_processRS(), fip_packet_activeBufSplit(), fip_sixlowpan_process(), fip_sixlowpanhc_compress(), and fip_udp_sendFinish().
#define fip_packet_getBufSize | ( | bufNum | ) | (fip_packet_get().buf[bufNum].usedSize) |
Get the size of data currently written into the buffer.
bufNum | Buffer to get size of |
Referenced by fip_icmp6_process(), fip_ip_process(), fip_ipUtils_checksum_tl(), fip_nd6_process(), fip_packet_activeBufSplit(), fip_packet_getBufSizes(), fip_sixlowpan_process(), and fip_sixlowpanhc_compress().
#define fip_packet_getFromBuf_Uint8Unaligned | ( | offset, | |||
bufNum | ) |
#define fip_packet_getFromIP6Hdr_isDestLinkLocal | ( | ) | (*(fip_packet_getIPBufPtr() + 24) == 0xFE) |
Referenced by fip_if6_selectSrcAddress(), fip_route6_getNextHop(), and fip_route6_process().
#define fip_packet_setAddrFlags | ( | type, | |||
flag, | |||||
value | ) | (fip_packet_get().type.flag = value) |
Set the address flags.
type | Either 'srcFlags' or 'destFlags' | |
flag | See fip_ip6addr_flags_t for flags | |
value | Value to set |
Referenced by fip_if6_isDestMyMulticast(), fip_ip_process(), fip_isDestUnspecified(), fip_isSrcUnspecified(), fip_nd6_generateNS(), and fip_packet_setToIP6Hdr_srcAddrUnspecified().
#define fip_packet_setAttr | ( | attr, | |||
value | ) | fip_packet_get().attr = (value) |
Set the value of an attribute to the active packet buffer.
attr | The attribute to set. Valid values are elements of the fip_packet_t struct. | |
value | The value to set this attribute to. |
Referenced by fip_icmp6_finalize(), fip_icmp6_process(), fip_if6_isDestMyUnicast(), fip_if_newPacketSetup(), fip_ip_process(), fip_ip_send(), fip_llgeneric_input(), fip_packet_activeDrop(), fip_packet_activeNew(), fip_packet_activeResponsePacket(), fip_route6_getNextHop(), fip_route6_process(), fip_sixlowpan_llInput(), fip_sixlowpan_process(), fip_task(), and fip_udp_sendFinish().
#define fip_packet_setBufSize | ( | bufNum, | |||
size | ) | (fip_packet_get().buf[bufNum].usedSize = size) |
Set the size of data currently written into the buffer.
bufNum | Buffer to get size of | |
size | Size of data to write |
Referenced by fip_icmp6_generateEchoRequest(), fip_icmp6_generateError(), fip_icmp6_process(), fip_if_newPacketSetup(), fip_ip_process(), fip_llgeneric_input(), fip_nd6_generateNA(), fip_nd6_generateNS(), fip_nd6_generateRA(), fip_nd6_generateRS(), fip_packet_activeBufSplit(), fip_sixlowpan_llInput(), fip_sixlowpanhc_compress(), and fip_udp_sendFinish().
#define fip_packet_setLLDestAddr | ( | addr, | |||
len | ) |
Value:
{fip_packet_get().destLLAddrLen = len; \ memcpy(fip_packet_get().destLLAddrOffset + fip_packet_getBufPtr(FIP_LLBUF), addr, len);}
Referenced by fip_ip_send(), fip_llgeneric_input(), fip_nd6_processNS(), fip_nd6_processRS(), fip_route6_getNextHop(), and fip_sixlowpan_llInput().
#define fip_packet_setLLSrcAddr | ( | addr, | |||
len | ) |
Value:
{fip_packet_get().srcLLAddrLen = len; \ memcpy(fip_packet_get().srcLLAddrOffset + fip_packet_getBufPtr(FIP_LLBUF), addr, len);}
Referenced by fip_ip_send(), fip_llgeneric_input(), and fip_sixlowpan_llInput().
enum fip_packetstate_t |
Valid states the active packet buffer can be in.
void fip_packet_activeBufSplit | ( | fip_bufnum_t | original, | |
fip_bufnum_t | new | |||
) |
Takes the specified origin buffer, and splits off all the free space (between allocSize and Size) and moves it to the new buffer, before using this function be SURE allocSize is set correctly in the 'original' buffer, and you don't have free space at the end.
original | Buffer to be split | |
new | Buffer to split free space into |
References fip_packet_getBufMaxSize, fip_packet_getBufPtr, fip_packet_getBufSize, and fip_packet_setBufSize.
Referenced by fip_ip_process().
void fip_packet_activeDrop | ( | void | ) |
Deallocate the active packet.
Note that calling this when there is no active packet, or the active packet has already been deallocated is safe.
References fip_packet_setAttr, and PS_UNUSED.
Referenced by fip_icmp6_generateError(), fip_icmp6_process(), fip_ip_process(), fip_ip_send(), fip_nd6_6lowpan_processNA(), fip_nd6_generateRA(), fip_nd6_generateRS(), fip_nd6_process(), fip_nd6_processNA(), fip_nd6_processNS(), fip_nd6_processRA(), fip_nd6_processRS(), fip_packet_activeQueuePacket(), fip_packet_activeResponsePacket(), fip_route6_getNextHop(), fip_route6_process(), fip_sixlowpan_process(), and fip_task().
fip_return_t fip_packet_activeNew | ( | fip_bufnum_t | bufnum, | |
uint16_t | length, | |||
fip_ifnum_t | ifnum | |||
) |
Allocate a new packet & make active.
bufnum | The buffer number which you are specifying the length for, any buffer greater than bufnum will have AllocSize of zero, any buffer smaller than bufnum will have the default AllocSize setup at interface intilization for this ifnum | |
length | Length of the buffer bufnum to allocate | |
ifnum | Interface number to generate packet on |
References fip_activePacket_buffer, fip_if_newPacketSetup(), fip_packet_activeQueuePacket(), fip_packet_getAttr, fip_packet_setAttr, PS_EMPTY, PS_UNUSED, RV_MEMORY_ERROR, RV_OK, RV_PARAMETER_ERROR, TRACE, TRACE_ADDRET, and TRACE_ADDVARH.
Referenced by fip_icmp6_generateEchoRequest(), fip_llgeneric_input(), fip_nd6_periodicIf(), fip_nd6_periodicUnicast(), fip_nd6_processNS(), fip_packet_activeResponsePacket(), and fip_sixlowpan_llInput().
fip_return_t fip_packet_activeResponsePacket | ( | fip_bufnum_t | bufnum, | |
unsigned int | length | |||
) |
Deallocate the current buffer, and allocate a new buffer.
The new buffer takes the source IP address and sets it as the destination.
length | Length of the IP part of the packet to allocate. |
References fip_ip6addr_t::addr, fip_activePacket_buffer, fip_if_newPacketSetup(), fip_ip6addr_cpy, fip_packet_activeDrop(), fip_packet_activeNew(), fip_packet_getAttr, fip_packet_getFromIP6Hdr_destPtr, fip_packet_getFromIP6Hdr_srcPtr, fip_packet_resetAddrFlags, fip_packet_setAttr, PS_EMPTY, RV_OK, RV_PARAMETER_ERROR, TRACE, TRACE_ADDRET, and TRACE_ADDVARH.
Referenced by fip_icmp6_generateError(), fip_nd6_processNS(), and fip_nd6_processRS().
void fip_packet_copyToIP6Hdr_destAddr | ( | const uint8_t *const | address | ) |
Copies 16 bytes from the pointer to the IPv6 Destination Address and resets all associated flags containing attributes about the address.
address | Pointer to address to copy from |
References fip_packet_getFromIP6Hdr_destPtr, and fip_packet_resetAddrFlags.
Referenced by fip_icmp6_generateEchoRequest(), and fip_nd6_generateNS().
void fip_packet_copyToIP6Hdr_srcAddr | ( | const uint8_t *const | address | ) |
Copies 16 bytes from the pointer to the IPv6 Source Address and resets all associated flags containing attributes about the address .
address | Pointer to address to copy from |
References fip_packet_getFromIP6Hdr_srcPtr, and fip_packet_resetAddrFlags.
Referenced by fip_if6_selectSrcAddress(), fip_nd6_generateNS(), fip_nd6_generateRA(), fip_nd6_generateRS(), fip_nd6_periodicUnicast(), and fip_nd6_processNS().
unsigned int fip_packet_getBufSizes | ( | fip_bufnum_t | first, | |
fip_bufnum_t | last | |||
) |
Returns the total size of all buffers specified, starting at 'first' up to but NOT INCLUDING 'last'.
first | ||
last |
References fip_packet_getBufSize.
Referenced by fip_icmp6_finalize(), fip_ipUtils_checksum_pseudo6hdr(), and fip_sixlowpan_process().
fip_return_t fip_packet_ptrBufCpyFromActive | ( | fip_packet_t * | packetPtr, | |
unsigned int | destOffset, | |||
uint8_t * | srcData, | |||
unsigned int | dataLen | |||
) |
Copy srcLen bytes from srcData to the FIP_IPHDRBUF of fragLocation offset from the start, extending the buffer if required to fit the data in.
fragLocation | Pointer to the packet to copy to | |
destOffset | Offset from the start of the buffer to write the bytes at | |
srcData | Source data | |
dataLen | Data length to copy |
References fip_packet_t::buf, RV_MEMORY_ERROR, and RV_OK.
Referenced by fip_ip_process().
uint8_t fip_activePacket_buffer[FIP_STATIC_BUF_SIZE] |
NB: There are two methods allowed to access the global fip_activePacket structure and directory.
Functions in this file, and macros that start with fip_packet(). You should NEVER access the structure directly, and if you feel compelled to do so it means either you are using something incorrectly, or fip is missing some function. The all-important active packet state.
Referenced by fip_packet_activeNew(), and fip_packet_activeResponsePacket().