Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
dtls_time.c@1:598a56fe116e, 2014-02-12 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Feb 12 09:30:16 2014 +0000
- Revision:
- 1:598a56fe116e
- Parent:
- 0:ff9ebe0cf0e9
Explicitly removed something instead of relying on MACRO to disable it. Mbed can't use it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:ff9ebe0cf0e9 | 1 | /* dtls -- a very basic DTLS implementation |
ashleymills | 0:ff9ebe0cf0e9 | 2 | * |
ashleymills | 0:ff9ebe0cf0e9 | 3 | * Copyright (C) 2011--2013 Olaf Bergmann <bergmann@tzi.org> |
ashleymills | 0:ff9ebe0cf0e9 | 4 | * |
ashleymills | 0:ff9ebe0cf0e9 | 5 | * Permission is hereby granted, free of charge, to any person |
ashleymills | 0:ff9ebe0cf0e9 | 6 | * obtaining a copy of this software and associated documentation |
ashleymills | 0:ff9ebe0cf0e9 | 7 | * files (the "Software"), to deal in the Software without |
ashleymills | 0:ff9ebe0cf0e9 | 8 | * restriction, including without limitation the rights to use, copy, |
ashleymills | 0:ff9ebe0cf0e9 | 9 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
ashleymills | 0:ff9ebe0cf0e9 | 10 | * of the Software, and to permit persons to whom the Software is |
ashleymills | 0:ff9ebe0cf0e9 | 11 | * furnished to do so, subject to the following conditions: |
ashleymills | 0:ff9ebe0cf0e9 | 12 | * |
ashleymills | 0:ff9ebe0cf0e9 | 13 | * The above copyright notice and this permission notice shall be |
ashleymills | 0:ff9ebe0cf0e9 | 14 | * included in all copies or substantial portions of the Software. |
ashleymills | 0:ff9ebe0cf0e9 | 15 | * |
ashleymills | 0:ff9ebe0cf0e9 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
ashleymills | 0:ff9ebe0cf0e9 | 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
ashleymills | 0:ff9ebe0cf0e9 | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ashleymills | 0:ff9ebe0cf0e9 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
ashleymills | 0:ff9ebe0cf0e9 | 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
ashleymills | 0:ff9ebe0cf0e9 | 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
ashleymills | 0:ff9ebe0cf0e9 | 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ashleymills | 0:ff9ebe0cf0e9 | 23 | * SOFTWARE. |
ashleymills | 0:ff9ebe0cf0e9 | 24 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 25 | |
ashleymills | 0:ff9ebe0cf0e9 | 26 | /** |
ashleymills | 0:ff9ebe0cf0e9 | 27 | * @file dtls_time.c |
ashleymills | 0:ff9ebe0cf0e9 | 28 | * @brief Clock Handling |
ashleymills | 0:ff9ebe0cf0e9 | 29 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 30 | |
ashleymills | 0:ff9ebe0cf0e9 | 31 | #include "dtls_time.h" |
ashleymills | 0:ff9ebe0cf0e9 | 32 | |
ashleymills | 0:ff9ebe0cf0e9 | 33 | |
ashleymills | 0:ff9ebe0cf0e9 | 34 | #ifdef MBED |
ashleymills | 0:ff9ebe0cf0e9 | 35 | #include "bsd_socket.h" |
ashleymills | 0:ff9ebe0cf0e9 | 36 | /** |
ashleymills | 0:ff9ebe0cf0e9 | 37 | * gettimeofday() not in mbed |
ashleymills | 0:ff9ebe0cf0e9 | 38 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 39 | void gettimeofday(struct timeval* t, void* timezone) |
ashleymills | 0:ff9ebe0cf0e9 | 40 | { |
ashleymills | 0:ff9ebe0cf0e9 | 41 | t->tv_sec = time(NULL); |
ashleymills | 0:ff9ebe0cf0e9 | 42 | t->tv_usec = 0; /* 1sec precision only */ |
ashleymills | 0:ff9ebe0cf0e9 | 43 | |
ashleymills | 0:ff9ebe0cf0e9 | 44 | } |
ashleymills | 0:ff9ebe0cf0e9 | 45 | |
ashleymills | 0:ff9ebe0cf0e9 | 46 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 47 | |
ashleymills | 0:ff9ebe0cf0e9 | 48 | #ifdef WITH_CONTIKI |
ashleymills | 0:ff9ebe0cf0e9 | 49 | clock_time_t dtls_clock_offset; |
ashleymills | 0:ff9ebe0cf0e9 | 50 | |
ashleymills | 0:ff9ebe0cf0e9 | 51 | void |
ashleymills | 0:ff9ebe0cf0e9 | 52 | dtls_clock_init(void) { |
ashleymills | 0:ff9ebe0cf0e9 | 53 | clock_init(); |
ashleymills | 0:ff9ebe0cf0e9 | 54 | dtls_clock_offset = clock_time(); |
ashleymills | 0:ff9ebe0cf0e9 | 55 | } |
ashleymills | 0:ff9ebe0cf0e9 | 56 | |
ashleymills | 0:ff9ebe0cf0e9 | 57 | void |
ashleymills | 0:ff9ebe0cf0e9 | 58 | dtls_ticks(dtls_tick_t *t) { |
ashleymills | 0:ff9ebe0cf0e9 | 59 | *t = clock_time(); |
ashleymills | 0:ff9ebe0cf0e9 | 60 | } |
ashleymills | 0:ff9ebe0cf0e9 | 61 | |
ashleymills | 0:ff9ebe0cf0e9 | 62 | #else /* WITH_CONTIKI */ |
ashleymills | 0:ff9ebe0cf0e9 | 63 | |
ashleymills | 0:ff9ebe0cf0e9 | 64 | time_t dtls_clock_offset; |
ashleymills | 0:ff9ebe0cf0e9 | 65 | |
ashleymills | 0:ff9ebe0cf0e9 | 66 | void |
ashleymills | 0:ff9ebe0cf0e9 | 67 | dtls_clock_init(void) { |
ashleymills | 0:ff9ebe0cf0e9 | 68 | #ifdef HAVE_TIME_H |
ashleymills | 0:ff9ebe0cf0e9 | 69 | dtls_clock_offset = time(NULL); |
ashleymills | 0:ff9ebe0cf0e9 | 70 | #else |
ashleymills | 0:ff9ebe0cf0e9 | 71 | # ifdef __GNUC__ |
ashleymills | 0:ff9ebe0cf0e9 | 72 | /* Issue a warning when using gcc. Other prepropressors do |
ashleymills | 0:ff9ebe0cf0e9 | 73 | * not seem to have a similar feature. */ |
ashleymills | 0:ff9ebe0cf0e9 | 74 | # warning "cannot initialize clock" |
ashleymills | 0:ff9ebe0cf0e9 | 75 | # endif |
ashleymills | 0:ff9ebe0cf0e9 | 76 | dtls_clock_offset = 0; |
ashleymills | 0:ff9ebe0cf0e9 | 77 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 78 | } |
ashleymills | 0:ff9ebe0cf0e9 | 79 | |
ashleymills | 0:ff9ebe0cf0e9 | 80 | |
ashleymills | 0:ff9ebe0cf0e9 | 81 | |
ashleymills | 0:ff9ebe0cf0e9 | 82 | void dtls_ticks(dtls_tick_t *t) { |
ashleymills | 0:ff9ebe0cf0e9 | 83 | #ifdef HAVE_SYS_TIME_H |
ashleymills | 0:ff9ebe0cf0e9 | 84 | struct timeval tv; |
ashleymills | 0:ff9ebe0cf0e9 | 85 | gettimeofday(&tv, NULL); |
ashleymills | 0:ff9ebe0cf0e9 | 86 | *t = (tv.tv_sec - dtls_clock_offset) * DTLS_TICKS_PER_SECOND |
ashleymills | 0:ff9ebe0cf0e9 | 87 | + (tv.tv_usec * DTLS_TICKS_PER_SECOND / 1000000); |
ashleymills | 0:ff9ebe0cf0e9 | 88 | #else |
ashleymills | 0:ff9ebe0cf0e9 | 89 | #error "clock not implemented" |
ashleymills | 0:ff9ebe0cf0e9 | 90 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 91 | } |
ashleymills | 0:ff9ebe0cf0e9 | 92 | |
ashleymills | 0:ff9ebe0cf0e9 | 93 | #endif /* WITH_CONTIKI */ |
ashleymills | 0:ff9ebe0cf0e9 | 94 | |
ashleymills | 0:ff9ebe0cf0e9 | 95 |