mbed port of tinydtls

Committer:
ashleymills
Date:
Fri Oct 11 08:46:21 2013 +0000
Revision:
1:bc8a649bad13
Parent:
0:04990d454f45
Cleaned up all the debug stuff I added finding the hash table bug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:04990d454f45 1 /* t_list -- tinydtls lists
ashleymills 0:04990d454f45 2 *
ashleymills 0:04990d454f45 3 * Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org>
ashleymills 0:04990d454f45 4 *
ashleymills 0:04990d454f45 5 * Permission is hereby granted, free of charge, to any person
ashleymills 0:04990d454f45 6 * obtaining a copy of this software and associated documentation
ashleymills 0:04990d454f45 7 * files (the "Software"), to deal in the Software without
ashleymills 0:04990d454f45 8 * restriction, including without limitation the rights to use, copy,
ashleymills 0:04990d454f45 9 * modify, merge, publish, distribute, sublicense, and/or sell copies
ashleymills 0:04990d454f45 10 * of the Software, and to permit persons to whom the Software is
ashleymills 0:04990d454f45 11 * furnished to do so, subject to the following conditions:
ashleymills 0:04990d454f45 12 *
ashleymills 0:04990d454f45 13 * The above copyright notice and this permission notice shall be
ashleymills 0:04990d454f45 14 * included in all copies or substantial portions of the Software.
ashleymills 0:04990d454f45 15 *
ashleymills 0:04990d454f45 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
ashleymills 0:04990d454f45 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
ashleymills 0:04990d454f45 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ashleymills 0:04990d454f45 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
ashleymills 0:04990d454f45 20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ashleymills 0:04990d454f45 21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
ashleymills 0:04990d454f45 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
ashleymills 0:04990d454f45 23 * SOFTWARE.
ashleymills 0:04990d454f45 24 */
ashleymills 0:04990d454f45 25
ashleymills 0:04990d454f45 26 /**
ashleymills 0:04990d454f45 27 * @file t_list.h
ashleymills 0:04990d454f45 28 * @brief Wrappers for list structures and functions
ashleymills 0:04990d454f45 29 */
ashleymills 0:04990d454f45 30
ashleymills 0:04990d454f45 31 #ifndef _DTLS_LIST_H_
ashleymills 0:04990d454f45 32 #define _DTLS_LIST_H_
ashleymills 0:04990d454f45 33
ashleymills 0:04990d454f45 34 #ifndef WITH_CONTIKI
ashleymills 0:04990d454f45 35 #include "uthash.h"
ashleymills 0:04990d454f45 36 #include "utlist.h"
ashleymills 0:04990d454f45 37
ashleymills 0:04990d454f45 38 /* We define list structures and utility functions to be compatible
ashleymills 0:04990d454f45 39 * with Contiki list structures. The Contiki list API is part of the
ashleymills 0:04990d454f45 40 * Contiki operating system, and therefore the following licensing
ashleymills 0:04990d454f45 41 * terms apply (taken from contiki/core/lib/list.h):
ashleymills 0:04990d454f45 42 *
ashleymills 0:04990d454f45 43 * Copyright (c) 2004, Swedish Institute of Computer Science.
ashleymills 0:04990d454f45 44 * All rights reserved.
ashleymills 0:04990d454f45 45 *
ashleymills 0:04990d454f45 46 * Redistribution and use in source and binary forms, with or without
ashleymills 0:04990d454f45 47 * modification, are permitted provided that the following conditions
ashleymills 0:04990d454f45 48 * are met:
ashleymills 0:04990d454f45 49 * 1. Redistributions of source code must retain the above copyright
ashleymills 0:04990d454f45 50 * notice, this list of conditions and the following disclaimer.
ashleymills 0:04990d454f45 51 * 2. Redistributions in binary form must reproduce the above copyright
ashleymills 0:04990d454f45 52 * notice, this list of conditions and the following disclaimer in the
ashleymills 0:04990d454f45 53 * documentation and/or other materials provided with the distribution.
ashleymills 0:04990d454f45 54 * 3. Neither the name of the Institute nor the names of its contributors
ashleymills 0:04990d454f45 55 * may be used to endorse or promote products derived from this software
ashleymills 0:04990d454f45 56 * without specific prior written permission.
ashleymills 0:04990d454f45 57 *
ashleymills 0:04990d454f45 58 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
ashleymills 0:04990d454f45 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ashleymills 0:04990d454f45 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ashleymills 0:04990d454f45 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
ashleymills 0:04990d454f45 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ashleymills 0:04990d454f45 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ashleymills 0:04990d454f45 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ashleymills 0:04990d454f45 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ashleymills 0:04990d454f45 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ashleymills 0:04990d454f45 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ashleymills 0:04990d454f45 68 * SUCH DAMAGE.
ashleymills 0:04990d454f45 69 *
ashleymills 0:04990d454f45 70 * This file is part of the Contiki operating system.
ashleymills 0:04990d454f45 71 *
ashleymills 0:04990d454f45 72 * Author: Adam Dunkels <adam@sics.se>
ashleymills 0:04990d454f45 73 *
ashleymills 0:04990d454f45 74 * $ Id: list.h,v 1.5 2010/09/13 13:31:00 adamdunkels Exp $
ashleymills 0:04990d454f45 75 */
ashleymills 0:04990d454f45 76
ashleymills 0:04990d454f45 77 typedef void **list_t;
ashleymills 0:04990d454f45 78 struct list {
ashleymills 0:04990d454f45 79 struct list *next;
ashleymills 0:04990d454f45 80 };
ashleymills 0:04990d454f45 81
ashleymills 0:04990d454f45 82 #define LIST_CONCAT(s1, s2) s1##s2
ashleymills 0:04990d454f45 83
ashleymills 0:04990d454f45 84 #define LIST_STRUCT(name) \
ashleymills 0:04990d454f45 85 void *LIST_CONCAT(name, _list); \
ashleymills 0:04990d454f45 86 list_t name
ashleymills 0:04990d454f45 87
ashleymills 0:04990d454f45 88 #define LIST_STRUCT_INIT(struct_ptr, name) { \
ashleymills 0:04990d454f45 89 (struct_ptr)->name = &((struct_ptr)->LIST_CONCAT(name,_list)); \
ashleymills 0:04990d454f45 90 (struct_ptr)->LIST_CONCAT(name,_list) = NULL; \
ashleymills 0:04990d454f45 91 }
ashleymills 0:04990d454f45 92
ashleymills 0:04990d454f45 93 static inline void *
ashleymills 0:04990d454f45 94 list_head(list_t list) {
ashleymills 0:04990d454f45 95 return *list;
ashleymills 0:04990d454f45 96 }
ashleymills 0:04990d454f45 97
ashleymills 0:04990d454f45 98 static inline void
ashleymills 0:04990d454f45 99 list_remove(list_t list, void *item) {
ashleymills 0:04990d454f45 100 LL_DELETE(*(struct list **)list, (struct list *)item);
ashleymills 0:04990d454f45 101 }
ashleymills 0:04990d454f45 102
ashleymills 0:04990d454f45 103 static inline void
ashleymills 0:04990d454f45 104 list_add(list_t list, void *item) {
ashleymills 0:04990d454f45 105 list_remove(list, item);
ashleymills 0:04990d454f45 106 LL_APPEND(*(struct list **)list, (struct list *)item);
ashleymills 0:04990d454f45 107 }
ashleymills 0:04990d454f45 108
ashleymills 0:04990d454f45 109 static inline void
ashleymills 0:04990d454f45 110 list_push(list_t list, void *item) {
ashleymills 0:04990d454f45 111 LL_PREPEND(*(struct list **)list, (struct list *)item);
ashleymills 0:04990d454f45 112 }
ashleymills 0:04990d454f45 113
ashleymills 0:04990d454f45 114 static inline void *
ashleymills 0:04990d454f45 115 list_pop(list_t list) {
ashleymills 0:04990d454f45 116 struct list *l;
ashleymills 0:04990d454f45 117 l = (struct list*)*list;
ashleymills 0:04990d454f45 118 if(l)
ashleymills 0:04990d454f45 119 list_remove(list, l);
ashleymills 0:04990d454f45 120
ashleymills 0:04990d454f45 121 return l;
ashleymills 0:04990d454f45 122 }
ashleymills 0:04990d454f45 123
ashleymills 0:04990d454f45 124 static inline void
ashleymills 0:04990d454f45 125 list_insert(list_t list, void *previtem, void *newitem) {
ashleymills 0:04990d454f45 126 if(previtem == NULL) {
ashleymills 0:04990d454f45 127 list_push(list, newitem);
ashleymills 0:04990d454f45 128 } else {
ashleymills 0:04990d454f45 129 ((struct list *)newitem)->next = ((struct list *)previtem)->next;
ashleymills 0:04990d454f45 130 ((struct list *)previtem)->next = (struct list *)newitem;
ashleymills 0:04990d454f45 131 }
ashleymills 0:04990d454f45 132 }
ashleymills 0:04990d454f45 133
ashleymills 0:04990d454f45 134 static inline void *
ashleymills 0:04990d454f45 135 list_item_next(void *item)
ashleymills 0:04990d454f45 136 {
ashleymills 0:04990d454f45 137 return item == NULL? NULL: ((struct list *)item)->next;
ashleymills 0:04990d454f45 138 }
ashleymills 0:04990d454f45 139
ashleymills 0:04990d454f45 140 #else /* WITH_CONTIKI */
ashleymills 0:04990d454f45 141 #include "list.h"
ashleymills 0:04990d454f45 142 #endif /* WITH_CONTIKI */
ashleymills 0:04990d454f45 143
ashleymills 0:04990d454f45 144 #endif /* _DTLS_LIST_H_ */
ashleymills 0:04990d454f45 145