mikroSDK Reference Manual
net_misc.h
Go to the documentation of this file.
1
31#ifndef _NET_MISC_H
32#define _NET_MISC_H
33
34//Forward declaration of NetTxAncillary structure
35struct _NetTxAncillary;
36#define NetTxAncillary struct _NetTxAncillary
37
38//Forward declaration of NetRxAncillary structure
39struct _NetRxAncillary;
40#define NetRxAncillary struct _NetRxAncillary
41
42//Dependencies
43#include "core/net.h"
44#include "core/ethernet.h"
45#include "core/ip.h"
46
47//Get a given bit of the PRNG internal state
48#define NET_RAND_GET_BIT(s, n) ((s[(n - 1) / 8] >> ((n - 1) % 8)) & 1)
49
50//Set a given bit of the PRNG internal state
51#define NET_RAND_STATE_SET_BIT(s, n, v) s[(n - 1) / 8] = \
52 (s[(n - 1) / 8] & ~(1 << ((n - 1) % 8))) | (v) << ((n - 1) % 8)
53
54//C++ guard
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59
64typedef void (*NetLinkChangeCallback)(NetInterface *interface,
65 bool_t linkState, void *param);
66
67
72typedef struct
73{
74 NetInterface *interface;
75 NetLinkChangeCallback callback;
76 void *param;
78
79
84typedef void (*NetTimerCallback)(void *param);
85
86
91typedef struct
92{
93 systime_t timerValue;
94 systime_t timerPeriod;
95 NetTimerCallback callback;
96 void *param;
98
99
104typedef struct
105{
106 uint32_t s;
107 uint32_t ns;
109
110
116{
117 uint8_t ttl;
118 uint8_t tos;
119 bool_t dontRoute;
120 bool_t routerAlert;
121#if (ETH_SUPPORT == ENABLED)
122 MacAddr srcMacAddr;
123 MacAddr destMacAddr;
124#endif
125#if (ETH_VLAN_SUPPORT == ENABLED)
126 int8_t vlanPcp;
127 int8_t vlanDei;
128#endif
129#if (ETH_VMAN_SUPPORT == ENABLED)
130 int8_t vmanPcp;
131 int8_t vmanDei;
132#endif
133#if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
134 uint8_t port;
135 uint32_t ports;
136 bool_t override;
137#endif
138#if (ETH_TIMESTAMP_SUPPORT == ENABLED)
139 int32_t timestampId;
140#endif
141};
142
143
149{
150 uint8_t ttl;
151 uint8_t tos;
152#if (ETH_SUPPORT == ENABLED)
153 MacAddr srcMacAddr;
154 MacAddr destMacAddr;
155 uint16_t ethType;
156#endif
157#if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
158 uint8_t port;
159#endif
160#if (ETH_TIMESTAMP_SUPPORT == ENABLED)
162#endif
163};
164
165
170typedef struct
171{
172 bool_t running;
173 systime_t startTime;
174 systime_t interval;
175} NetTimer;
176
177
182typedef struct
183{
184 uint16_t counter;
185 uint8_t s[36];
187
188
189//Global constants
190extern const NetTxAncillary NET_DEFAULT_TX_ANCILLARY;
191extern const NetRxAncillary NET_DEFAULT_RX_ANCILLARY;
192
193//TCP/IP stack related functions
194error_t netAttachLinkChangeCallback(NetInterface *interface,
195 NetLinkChangeCallback callback, void *param);
196
197error_t netDetachLinkChangeCallback(NetInterface *interface,
198 NetLinkChangeCallback callback, void *param);
199
200void netProcessLinkChange(NetInterface *interface);
201
202error_t netAttachTimerCallback(systime_t period, NetTimerCallback callback,
203 void *param);
204
205error_t netDetachTimerCallback(NetTimerCallback callback, void *param);
206
207void netTick(void);
208
209void netStartTimer(NetTimer *timer, systime_t interval);
210void netStopTimer(NetTimer *timer);
211bool_t netTimerRunning(NetTimer *timer);
212bool_t netTimerExpired(NetTimer *timer);
213
214void netInitRand(void);
215uint32_t netGenerateRand(void);
216uint32_t netGenerateRandRange(uint32_t min, uint32_t max);
217void netGenerateRandData(uint8_t *data, size_t length);
218uint32_t netGenerateRandBit(NetRandState *state);
219
220//C++ guard
221#ifdef __cplusplus
222}
223#endif
224
225#endif
error_t
Error codes.
Definition error.h:43
Ethernet.
IPv4 and IPv6 common routines.
TCP/IP stack core.
void(* NetLinkChangeCallback)(NetInterface *interface, bool_t linkState, void *param)
Link change callback.
Definition net_misc.h:64
void(* NetTimerCallback)(void *param)
Timer callback.
Definition net_misc.h:84
uint32_t systime_t
System time.
Definition os_port_none.h:90
Link change callback entry.
Definition net_misc.h:73
Pseudo-random number generator state.
Definition net_misc.h:183
Timer callback entry.
Definition net_misc.h:92
Timer.
Definition net_misc.h:171
Timestamp.
Definition net_misc.h:105
Additional options passed to the stack (RX path)
Definition net_misc.h:149
MacAddr destMacAddr
Destination MAC address.
Definition net_misc.h:154
NetTimestamp timestamp
Captured time stamp.
Definition net_misc.h:161
uint8_t port
Ingress port identifier.
Definition net_misc.h:158
uint8_t tos
Type-of-service value.
Definition net_misc.h:151
uint16_t ethType
Ethernet type field.
Definition net_misc.h:155
uint8_t ttl
Time-to-live value.
Definition net_misc.h:150
MacAddr srcMacAddr
Source MAC address.
Definition net_misc.h:153
Additional options passed to the stack (TX path)
Definition net_misc.h:116
bool_t dontRoute
Do not send the packet via a router.
Definition net_misc.h:119
MacAddr destMacAddr
Destination MAC address.
Definition net_misc.h:123
uint8_t port
Egress port identifier.
Definition net_misc.h:134
int8_t vmanDei
Drop eligible indicator.
Definition net_misc.h:131
uint8_t tos
Type-of-service value.
Definition net_misc.h:118
uint32_t ports
Egress port map.
Definition net_misc.h:135
uint8_t ttl
Time-to-live value.
Definition net_misc.h:117
int8_t vmanPcp
VMAN priority (802.1ad)
Definition net_misc.h:130
int8_t vlanPcp
VLAN priority (802.1Q)
Definition net_misc.h:126
int32_t timestampId
Unique identifier for hardware time stamping.
Definition net_misc.h:139
bool_t routerAlert
Add an IP Router Alert option.
Definition net_misc.h:120
MacAddr srcMacAddr
Source MAC address.
Definition net_misc.h:122
int8_t vlanDei
Drop eligible indicator.
Definition net_misc.h:127