Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed tinydtls
Fork of tinydtls_test_ethernet by
tinydtls/netq.h@0:6ae42a2aff75, 2013-10-09 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Oct 09 14:48:52 2013 +0000
- Revision:
- 0:6ae42a2aff75
Test program for mbed port of tinydtls
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ashleymills | 0:6ae42a2aff75 | 1 | /* netq.h -- Simple packet queue |
| ashleymills | 0:6ae42a2aff75 | 2 | * |
| ashleymills | 0:6ae42a2aff75 | 3 | * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org> |
| ashleymills | 0:6ae42a2aff75 | 4 | * |
| ashleymills | 0:6ae42a2aff75 | 5 | * This file is part of the library tinyDTLS. Please see the file |
| ashleymills | 0:6ae42a2aff75 | 6 | * LICENSE for terms of use. |
| ashleymills | 0:6ae42a2aff75 | 7 | */ |
| ashleymills | 0:6ae42a2aff75 | 8 | |
| ashleymills | 0:6ae42a2aff75 | 9 | #ifndef _NETQ_H_ |
| ashleymills | 0:6ae42a2aff75 | 10 | #define _NETQ_H_ |
| ashleymills | 0:6ae42a2aff75 | 11 | |
| ashleymills | 0:6ae42a2aff75 | 12 | #include "config.h" |
| ashleymills | 0:6ae42a2aff75 | 13 | #include "global.h" |
| ashleymills | 0:6ae42a2aff75 | 14 | //#include "dtls.h" |
| ashleymills | 0:6ae42a2aff75 | 15 | #include "time.h" |
| ashleymills | 0:6ae42a2aff75 | 16 | #include "peer.h" |
| ashleymills | 0:6ae42a2aff75 | 17 | |
| ashleymills | 0:6ae42a2aff75 | 18 | /** |
| ashleymills | 0:6ae42a2aff75 | 19 | * \defgroup netq Network Packet Queue |
| ashleymills | 0:6ae42a2aff75 | 20 | * The netq utility functions implement an ordered queue of data packets |
| ashleymills | 0:6ae42a2aff75 | 21 | * to send over the network and can also be used to queue received packets |
| ashleymills | 0:6ae42a2aff75 | 22 | * from the network. |
| ashleymills | 0:6ae42a2aff75 | 23 | * @{ |
| ashleymills | 0:6ae42a2aff75 | 24 | */ |
| ashleymills | 0:6ae42a2aff75 | 25 | |
| ashleymills | 0:6ae42a2aff75 | 26 | #ifndef NETQ_MAXCNT |
| ashleymills | 0:6ae42a2aff75 | 27 | #define NETQ_MAXCNT 4 /**< maximum number of elements in netq structure */ |
| ashleymills | 0:6ae42a2aff75 | 28 | #endif |
| ashleymills | 0:6ae42a2aff75 | 29 | |
| ashleymills | 0:6ae42a2aff75 | 30 | /** |
| ashleymills | 0:6ae42a2aff75 | 31 | * Datagrams in the netq_t structure have a fixed maximum size of |
| ashleymills | 0:6ae42a2aff75 | 32 | * DTLS_MAX_BUF to simplify memory management on constrained nodes. */ |
| ashleymills | 0:6ae42a2aff75 | 33 | typedef unsigned char netq_packet_t[DTLS_MAX_BUF]; |
| ashleymills | 0:6ae42a2aff75 | 34 | |
| ashleymills | 0:6ae42a2aff75 | 35 | typedef struct netq_t { |
| ashleymills | 0:6ae42a2aff75 | 36 | struct netq_t *next; |
| ashleymills | 0:6ae42a2aff75 | 37 | |
| ashleymills | 0:6ae42a2aff75 | 38 | clock_time_t t; /**< when to send PDU for the next time */ |
| ashleymills | 0:6ae42a2aff75 | 39 | unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */ |
| ashleymills | 0:6ae42a2aff75 | 40 | unsigned int timeout; /**< randomized timeout value */ |
| ashleymills | 0:6ae42a2aff75 | 41 | |
| ashleymills | 0:6ae42a2aff75 | 42 | dtls_peer_t *peer; /**< remote address */ |
| ashleymills | 0:6ae42a2aff75 | 43 | |
| ashleymills | 0:6ae42a2aff75 | 44 | size_t length; /**< actual length of data */ |
| ashleymills | 0:6ae42a2aff75 | 45 | netq_packet_t data; /**< the datagram to send */ |
| ashleymills | 0:6ae42a2aff75 | 46 | } netq_t; |
| ashleymills | 0:6ae42a2aff75 | 47 | |
| ashleymills | 0:6ae42a2aff75 | 48 | /** |
| ashleymills | 0:6ae42a2aff75 | 49 | * Adds a node to the given queue, ordered by their time-stamp t. |
| ashleymills | 0:6ae42a2aff75 | 50 | * This function returns @c 0 on error, or non-zero if @p node has |
| ashleymills | 0:6ae42a2aff75 | 51 | * been added successfully. |
| ashleymills | 0:6ae42a2aff75 | 52 | * |
| ashleymills | 0:6ae42a2aff75 | 53 | * @param queue A pointer to the queue head where @p node will be added. |
| ashleymills | 0:6ae42a2aff75 | 54 | * @param node The new item to add. |
| ashleymills | 0:6ae42a2aff75 | 55 | * @return @c 0 on error, or non-zero if the new item was added. |
| ashleymills | 0:6ae42a2aff75 | 56 | */ |
| ashleymills | 0:6ae42a2aff75 | 57 | int netq_insert_node(netq_t **queue, netq_t *node); |
| ashleymills | 0:6ae42a2aff75 | 58 | |
| ashleymills | 0:6ae42a2aff75 | 59 | /** Destroys specified node and releases any memory that was allocated |
| ashleymills | 0:6ae42a2aff75 | 60 | * for the associated datagram. */ |
| ashleymills | 0:6ae42a2aff75 | 61 | void netq_node_free(netq_t *node); |
| ashleymills | 0:6ae42a2aff75 | 62 | |
| ashleymills | 0:6ae42a2aff75 | 63 | /** Removes all items from given queue and frees the allocated storage */ |
| ashleymills | 0:6ae42a2aff75 | 64 | void netq_delete_all(netq_t *queue); |
| ashleymills | 0:6ae42a2aff75 | 65 | |
| ashleymills | 0:6ae42a2aff75 | 66 | /** Creates a new node suitable for adding to a netq_t queue. */ |
| ashleymills | 0:6ae42a2aff75 | 67 | netq_t *netq_node_new(); |
| ashleymills | 0:6ae42a2aff75 | 68 | |
| ashleymills | 0:6ae42a2aff75 | 69 | /** |
| ashleymills | 0:6ae42a2aff75 | 70 | * Returns a pointer to the first item in given queue or NULL if |
| ashleymills | 0:6ae42a2aff75 | 71 | * empty. |
| ashleymills | 0:6ae42a2aff75 | 72 | */ |
| ashleymills | 0:6ae42a2aff75 | 73 | netq_t *netq_head(netq_t **queue); |
| ashleymills | 0:6ae42a2aff75 | 74 | |
| ashleymills | 0:6ae42a2aff75 | 75 | /** |
| ashleymills | 0:6ae42a2aff75 | 76 | * Removes the first item in given queue and returns a pointer to the |
| ashleymills | 0:6ae42a2aff75 | 77 | * removed element. If queue is empty when netq_pop_first() is called, |
| ashleymills | 0:6ae42a2aff75 | 78 | * this function returns NULL. |
| ashleymills | 0:6ae42a2aff75 | 79 | */ |
| ashleymills | 0:6ae42a2aff75 | 80 | netq_t *netq_pop_first(netq_t **queue); |
| ashleymills | 0:6ae42a2aff75 | 81 | |
| ashleymills | 0:6ae42a2aff75 | 82 | /**@}*/ |
| ashleymills | 0:6ae42a2aff75 | 83 | |
| ashleymills | 0:6ae42a2aff75 | 84 | #endif /* _NETQ_H_ */ |
