mikroSDK Reference Manual
udp.h
Go to the documentation of this file.
1
31#ifndef _UDP_H
32#define _UDP_H
33
34//Dependencies
35#include "core/net.h"
36#include "core/tcp.h"
37
38//UDP support
39#ifndef UDP_SUPPORT
40 #define UDP_SUPPORT ENABLED
41#elif (UDP_SUPPORT != ENABLED && UDP_SUPPORT != DISABLED)
42 #error UDP_SUPPORT parameter is not valid
43#endif
44
45//Maximum number of callback functions that can be registered
46//to process incoming UDP datagrams
47#ifndef UDP_CALLBACK_TABLE_SIZE
48 #define UDP_CALLBACK_TABLE_SIZE 10
49#elif (UDP_CALLBACK_TABLE_SIZE < 1)
50 #error UDP_CALLBACK_TABLE_SIZE parameter is not valid
51#endif
52
53//Receive queue depth for connectionless sockets
54#ifndef UDP_RX_QUEUE_SIZE
55 #define UDP_RX_QUEUE_SIZE 4
56#elif (UDP_RX_QUEUE_SIZE < 1)
57 #error UDP_RX_QUEUE_SIZE parameter is not valid
58#endif
59
60//C++ guard
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65
66//CodeWarrior or Win32 compiler?
67#if defined(__CWCC__) || defined(_WIN32)
68 #pragma pack(push, 1)
69#endif
70
71
77{
78 uint16_t srcPort; //0-1
79 uint16_t destPort; //2-3
80 uint16_t length; //4-5
81 uint16_t checksum; //6-7
82 uint8_t data[]; //8
83} UdpHeader;
84
85
86//CodeWarrior or Win32 compiler?
87#if defined(__CWCC__) || defined(_WIN32)
88 #pragma pack(pop)
89#endif
90
91
96typedef void (*UdpRxCallback)(NetInterface *interface,
97 const IpPseudoHeader *pseudoHeader, const UdpHeader *header,
98 const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
99 void *param);
100
101
106typedef struct
107{
108 NetInterface *interface;
109 uint16_t port;
110 UdpRxCallback callback;
111 void *param;
113
114
115//Global variables
116extern UdpRxCallbackEntry udpCallbackTable[UDP_CALLBACK_TABLE_SIZE];
117
118//UDP related functions
119error_t udpInit(void);
120uint16_t udpGetDynamicPort(void);
121
122error_t udpProcessDatagram(NetInterface *interface,
123 const IpPseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset,
124 const NetRxAncillary *ancillary);
125
126error_t udpSendDatagram(Socket *socket, const SocketMsg *message, uint_t flags);
127
128error_t udpSendBuffer(NetInterface *interface, const IpAddr *srcIpAddr,
129 uint16_t srcPort, const IpAddr *destIpAddr, uint16_t destPort,
130 NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
131
132error_t udpReceiveDatagram(Socket *socket, SocketMsg *message, uint_t flags);
133
134NetBuffer *udpAllocBuffer(size_t length, size_t *offset);
135
136void udpUpdateEvents(Socket *socket);
137
138error_t udpAttachRxCallback(NetInterface *interface, uint16_t port,
139 UdpRxCallback callback, void *param);
140
141error_t udpDetachRxCallback(NetInterface *interface, uint16_t port);
142
143error_t udpInvokeRxCallback(NetInterface *interface,
144 const IpPseudoHeader *pseudoHeader, const UdpHeader *header,
145 const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary);
146
147void udpDumpHeader(const UdpHeader *datagram);
148
149//C++ guard
150#ifdef __cplusplus
151}
152#endif
153
154#endif
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
IP network address.
Definition ip.h:72
IP pseudo header.
Definition ip.h:91
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89
Message and ancillary data.
Definition socket.h:228
UDP receive callback entry.
Definition udp.h:107
TCP (Transmission Control Protocol)
void(* UdpRxCallback)(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *header, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
UDP receive callback.
Definition udp.h:96
typedef __packed_struct
UDP header.
Definition udp.h:77