net_misc.h File Reference

Helper functions for TCP/IP stack. More...

#include "core/net.h"
#include "core/ethernet.h"
#include "core/ip.h"

Go to the source code of this file.

Data Structures

struct  NetLinkChangeCallbackEntry
 Link change callback entry. More...
 
struct  NetTimerCallbackEntry
 Timer callback entry. More...
 
struct  NetTimestamp
 Timestamp. More...
 
struct  _NetTxAncillary
 Additional options passed to the stack (TX path) More...
 
struct  _NetRxAncillary
 Additional options passed to the stack (RX path) More...
 
struct  NetRandState
 Pseudo-random number generator state. More...
 

Macros

#define NetTxAncillary   struct _NetTxAncillary
 
#define NetRxAncillary   struct _NetRxAncillary
 
#define NET_RAND_GET_BIT(s, n)   ((s[(n - 1) / 8] >> ((n - 1) % 8)) & 1)
 
#define NET_RAND_STATE_SET_BIT(s, n, v)
 

Typedefs

typedef void(* NetLinkChangeCallback) (NetInterface *interface, bool_t linkState, void *param)
 Link change callback. More...
 
typedef void(* NetTimerCallback) (void *param)
 Timer callback. More...
 

Functions

error_t netAttachLinkChangeCallback (NetInterface *interface, NetLinkChangeCallback callback, void *param)
 Register link change callback. More...
 
error_t netDetachLinkChangeCallback (NetInterface *interface, NetLinkChangeCallback callback, void *param)
 Unregister link change callback. More...
 
void netProcessLinkChange (NetInterface *interface)
 Process link state change event. More...
 
error_t netAttachTimerCallback (systime_t period, NetTimerCallback callback, void *param)
 Register timer callback. More...
 
error_t netDetachTimerCallback (NetTimerCallback callback, void *param)
 Unregister timer callback. More...
 
void netTick (void)
 Manage TCP/IP timers. More...
 
void netInitRand (void)
 PRNG initialization. More...
 
uint32_t netGetRand (void)
 Generate a random 32-bit value. More...
 
int32_t netGetRandRange (int32_t min, int32_t max)
 Get a random value in the specified range. More...
 
uint32_t netGetRandBit (NetRandState *state)
 Generate one random bit. More...
 

Variables

const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
 
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
 

Detailed Description

Helper functions for TCP/IP stack.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2021 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.0.2

Definition in file net_misc.h.

Macro Definition Documentation

◆ NET_RAND_GET_BIT

#define NET_RAND_GET_BIT (   s,
  n 
)    ((s[(n - 1) / 8] >> ((n - 1) % 8)) & 1)

Definition at line 48 of file net_misc.h.

◆ NET_RAND_STATE_SET_BIT

#define NET_RAND_STATE_SET_BIT (   s,
  n,
 
)
Value:
s[(n - 1) / 8] = \
(s[(n - 1) / 8] & ~(1 << ((n - 1) % 8))) | (v) << ((n - 1) % 8)

Definition at line 51 of file net_misc.h.

◆ NetRxAncillary

#define NetRxAncillary   struct _NetRxAncillary

Definition at line 40 of file net_misc.h.

◆ NetTxAncillary

#define NetTxAncillary   struct _NetTxAncillary

Definition at line 36 of file net_misc.h.

Typedef Documentation

◆ NetLinkChangeCallback

typedef void(* NetLinkChangeCallback) (NetInterface *interface, bool_t linkState, void *param)

Link change callback.

Definition at line 64 of file net_misc.h.

◆ NetTimerCallback

typedef void(* NetTimerCallback) (void *param)

Timer callback.

Definition at line 84 of file net_misc.h.

Function Documentation

◆ netAttachLinkChangeCallback()

error_t netAttachLinkChangeCallback ( NetInterface interface,
NetLinkChangeCallback  callback,
void *  param 
)

Register link change callback.

Parameters
[in]interfaceUnderlying network interface
[in]callbackCallback function to be called when the link state changed
[in]paramCallback function parameter
Returns
Error code

Definition at line 120 of file net_misc.c.

◆ netAttachTimerCallback()

error_t netAttachTimerCallback ( systime_t  period,
NetTimerCallback  callback,
void *  param 
)

Register timer callback.

Parameters
[in]periodTimer reload value, in milliseconds
[in]callbackCallback function to be called when the timer expires
[in]paramCallback function parameter
Returns
Error code

Definition at line 337 of file net_misc.c.

◆ netDetachLinkChangeCallback()

error_t netDetachLinkChangeCallback ( NetInterface interface,
NetLinkChangeCallback  callback,
void *  param 
)

Unregister link change callback.

Parameters
[in]interfaceUnderlying network interface
[in]callbackCallback function to be unregistered
[in]paramCallback function parameter
Returns
Error code

Definition at line 158 of file net_misc.c.

◆ netDetachTimerCallback()

error_t netDetachTimerCallback ( NetTimerCallback  callback,
void *  param 
)

Unregister timer callback.

Parameters
[in]callbackCallback function to be unregistered
[in]paramCallback function parameter
Returns
Error code

Definition at line 375 of file net_misc.c.

◆ netGetRand()

uint32_t netGetRand ( void  )

Generate a random 32-bit value.

Returns
Random value

Definition at line 795 of file net_misc.c.

◆ netGetRandBit()

uint32_t netGetRandBit ( NetRandState state)

Generate one random bit.

Parameters
[in]statePointer to the PRNG state
Returns
Key stream bit

Definition at line 848 of file net_misc.c.

◆ netGetRandRange()

int32_t netGetRandRange ( int32_t  min,
int32_t  max 
)

Get a random value in the specified range.

Parameters
[in]minLower bound
[in]maxUpper bound
Returns
Random value in the specified range

Definition at line 821 of file net_misc.c.

◆ netInitRand()

void netInitRand ( void  )

PRNG initialization.

Definition at line 739 of file net_misc.c.

◆ netProcessLinkChange()

void netProcessLinkChange ( NetInterface interface)

Process link state change event.

Parameters
[in]interfaceUnderlying network interface

Definition at line 191 of file net_misc.c.

◆ netTick()

void netTick ( void  )

Manage TCP/IP timers.

Definition at line 406 of file net_misc.c.

Variable Documentation

◆ NET_DEFAULT_RX_ANCILLARY

const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
extern

Definition at line 96 of file net_misc.c.

◆ NET_DEFAULT_TX_ANCILLARY

const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
extern

Definition at line 68 of file net_misc.c.

uint8_t n
uint8_t s