Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pico_frame.h Source File

pico_frame.h

00001 /*********************************************************************
00002    PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
00003    See LICENSE and COPYING for usage.
00004 
00005  *********************************************************************/
00006 #ifndef INCLUDE_PICO_FRAME
00007 #define INCLUDE_PICO_FRAME
00008 #include "pico_config.h"
00009 
00010 
00011 #define PICO_FRAME_FLAG_BCAST               (0x01)
00012 #define PICO_FRAME_FLAG_EXT_BUFFER          (0x02)
00013 #define PICO_FRAME_FLAG_EXT_USAGE_COUNTER   (0x04)
00014 #define PICO_FRAME_FLAG_SACKED              (0x80)
00015 #define IS_BCAST(f) ((f->flags & PICO_FRAME_FLAG_BCAST) == PICO_FRAME_FLAG_BCAST)
00016 
00017 
00018 struct pico_socket;
00019 
00020 
00021 struct pico_frame {
00022 
00023     /* Connector for queues */
00024     struct pico_frame *next;
00025 
00026     /* Start of the whole buffer, total frame length. */
00027     unsigned char *buffer;
00028     uint32_t buffer_len;
00029 
00030     /* For outgoing packets: this is the meaningful buffer. */
00031     unsigned char *start;
00032     uint32_t len;
00033 
00034     /* Pointer to usage counter */
00035     uint32_t *usage_count;
00036 
00037     /* Pointer to protocol headers */
00038     uint8_t *datalink_hdr;
00039 
00040     uint8_t *net_hdr;
00041     uint16_t net_len;
00042     uint8_t *transport_hdr;
00043     uint16_t transport_len;
00044     uint8_t *app_hdr;
00045     uint16_t app_len;
00046 
00047     /* Pointer to the phisical device this packet belongs to.
00048      * Should be valid in both routing directions
00049      */
00050     struct pico_device *dev;
00051 
00052     pico_time timestamp;
00053 
00054     /* Failures due to bad datalink addressing. */
00055     uint16_t failure_count;
00056 
00057     /* Protocol over IP */
00058     uint8_t proto;
00059 
00060     /* PICO_FRAME_FLAG_* */
00061     uint8_t flags;
00062 
00063     /* Pointer to payload */
00064     unsigned char *payload;
00065     uint16_t payload_len;
00066 
00067 #if defined(PICO_SUPPORT_IPV4FRAG) || defined(PICO_SUPPORT_IPV6FRAG)
00068     /* Payload fragmentation info */
00069     uint16_t frag;
00070 #endif
00071 
00072     /* Pointer to socket */
00073     struct pico_socket *sock;
00074 
00075     /* Pointer to transport info, used to store remote UDP endpoint (IP + port) */
00076     void *info;
00077 
00078     /*Priority. "best-effort" priority, the default value is 0. Priority can be in between -10 and +10*/
00079     int8_t priority;
00080     uint8_t transport_flags_saved;
00081 
00082     /* Callback to notify listener when the buffer has been discarded */
00083     void (*notify_free)(uint8_t *);
00084 
00085     uint8_t send_ttl; /* Special TTL/HOPS value, 0 = auto assign */
00086     uint8_t send_tos; /* Type of service */
00087 };
00088 
00089 /** frame alloc/dealloc/copy **/
00090 void pico_frame_discard(struct pico_frame *f);
00091 struct pico_frame *pico_frame_copy(struct pico_frame *f);
00092 struct pico_frame *pico_frame_deepcopy(struct pico_frame *f);
00093 struct pico_frame *pico_frame_alloc(uint32_t size);
00094 int pico_frame_grow(struct pico_frame *f, uint32_t size);
00095 struct pico_frame *pico_frame_alloc_skeleton(uint32_t size, int ext_buffer);
00096 int pico_frame_skeleton_set_buffer(struct pico_frame *f, void *buf);
00097 uint16_t pico_checksum(void *inbuf, uint32_t len);
00098 uint16_t pico_dualbuffer_checksum(void *b1, uint32_t len1, void *b2, uint32_t len2);
00099 
00100 static inline int pico_is_digit(char c)
00101 {
00102     if (c < '0' || c > '9')
00103         return 0;
00104 
00105     return 1;
00106 }
00107 
00108 static inline int pico_is_hex(char c)
00109 {
00110     if (c >= '0' && c <= '9')
00111         return 1;
00112 
00113     if (c >= 'a' && c <= 'f')
00114         return 1;
00115 
00116     if (c >= 'A' && c <= 'F')
00117         return 1;
00118 
00119     return 0;
00120 }
00121 
00122 #endif