SSL/TLS Library
CyaSSL is SSL/TLS library for embedded systems.
ctaocrypt/src/port.c@0:9d17e4342598, 2014-04-20 (annotated)
- Committer:
- wolfSSL
- Date:
- Sun Apr 20 12:40:57 2014 +0000
- Revision:
- 0:9d17e4342598
CyaSSL SSL/TLS Library 2.9.4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:9d17e4342598 | 1 | /* port.c |
wolfSSL | 0:9d17e4342598 | 2 | * |
wolfSSL | 0:9d17e4342598 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
wolfSSL | 0:9d17e4342598 | 4 | * |
wolfSSL | 0:9d17e4342598 | 5 | * This file is part of CyaSSL. |
wolfSSL | 0:9d17e4342598 | 6 | * |
wolfSSL | 0:9d17e4342598 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
wolfSSL | 0:9d17e4342598 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 0:9d17e4342598 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 0:9d17e4342598 | 10 | * (at your option) any later version. |
wolfSSL | 0:9d17e4342598 | 11 | * |
wolfSSL | 0:9d17e4342598 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
wolfSSL | 0:9d17e4342598 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 0:9d17e4342598 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 0:9d17e4342598 | 15 | * GNU General Public License for more details. |
wolfSSL | 0:9d17e4342598 | 16 | * |
wolfSSL | 0:9d17e4342598 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 0:9d17e4342598 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 0:9d17e4342598 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
wolfSSL | 0:9d17e4342598 | 20 | */ |
wolfSSL | 0:9d17e4342598 | 21 | |
wolfSSL | 0:9d17e4342598 | 22 | #ifdef HAVE_CONFIG_H |
wolfSSL | 0:9d17e4342598 | 23 | #include <config.h> |
wolfSSL | 0:9d17e4342598 | 24 | #endif |
wolfSSL | 0:9d17e4342598 | 25 | |
wolfSSL | 0:9d17e4342598 | 26 | #include <cyassl/ctaocrypt/settings.h> |
wolfSSL | 0:9d17e4342598 | 27 | #include <cyassl/ctaocrypt/types.h> |
wolfSSL | 0:9d17e4342598 | 28 | #include <cyassl/ctaocrypt/error-crypt.h> |
wolfSSL | 0:9d17e4342598 | 29 | |
wolfSSL | 0:9d17e4342598 | 30 | |
wolfSSL | 0:9d17e4342598 | 31 | #ifdef _MSC_VER |
wolfSSL | 0:9d17e4342598 | 32 | /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */ |
wolfSSL | 0:9d17e4342598 | 33 | #pragma warning(disable: 4996) |
wolfSSL | 0:9d17e4342598 | 34 | #endif |
wolfSSL | 0:9d17e4342598 | 35 | |
wolfSSL | 0:9d17e4342598 | 36 | |
wolfSSL | 0:9d17e4342598 | 37 | |
wolfSSL | 0:9d17e4342598 | 38 | #ifdef SINGLE_THREADED |
wolfSSL | 0:9d17e4342598 | 39 | |
wolfSSL | 0:9d17e4342598 | 40 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 41 | { |
wolfSSL | 0:9d17e4342598 | 42 | (void)m; |
wolfSSL | 0:9d17e4342598 | 43 | return 0; |
wolfSSL | 0:9d17e4342598 | 44 | } |
wolfSSL | 0:9d17e4342598 | 45 | |
wolfSSL | 0:9d17e4342598 | 46 | |
wolfSSL | 0:9d17e4342598 | 47 | int FreeMutex(CyaSSL_Mutex *m) |
wolfSSL | 0:9d17e4342598 | 48 | { |
wolfSSL | 0:9d17e4342598 | 49 | (void)m; |
wolfSSL | 0:9d17e4342598 | 50 | return 0; |
wolfSSL | 0:9d17e4342598 | 51 | } |
wolfSSL | 0:9d17e4342598 | 52 | |
wolfSSL | 0:9d17e4342598 | 53 | |
wolfSSL | 0:9d17e4342598 | 54 | int LockMutex(CyaSSL_Mutex *m) |
wolfSSL | 0:9d17e4342598 | 55 | { |
wolfSSL | 0:9d17e4342598 | 56 | (void)m; |
wolfSSL | 0:9d17e4342598 | 57 | return 0; |
wolfSSL | 0:9d17e4342598 | 58 | } |
wolfSSL | 0:9d17e4342598 | 59 | |
wolfSSL | 0:9d17e4342598 | 60 | |
wolfSSL | 0:9d17e4342598 | 61 | int UnLockMutex(CyaSSL_Mutex *m) |
wolfSSL | 0:9d17e4342598 | 62 | { |
wolfSSL | 0:9d17e4342598 | 63 | (void)m; |
wolfSSL | 0:9d17e4342598 | 64 | return 0; |
wolfSSL | 0:9d17e4342598 | 65 | } |
wolfSSL | 0:9d17e4342598 | 66 | |
wolfSSL | 0:9d17e4342598 | 67 | #else /* MULTI_THREAD */ |
wolfSSL | 0:9d17e4342598 | 68 | |
wolfSSL | 0:9d17e4342598 | 69 | #if defined(FREERTOS) |
wolfSSL | 0:9d17e4342598 | 70 | |
wolfSSL | 0:9d17e4342598 | 71 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 72 | { |
wolfSSL | 0:9d17e4342598 | 73 | int iReturn; |
wolfSSL | 0:9d17e4342598 | 74 | |
wolfSSL | 0:9d17e4342598 | 75 | *m = ( CyaSSL_Mutex ) xSemaphoreCreateMutex(); |
wolfSSL | 0:9d17e4342598 | 76 | if( *m != NULL ) |
wolfSSL | 0:9d17e4342598 | 77 | iReturn = 0; |
wolfSSL | 0:9d17e4342598 | 78 | else |
wolfSSL | 0:9d17e4342598 | 79 | iReturn = BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 80 | |
wolfSSL | 0:9d17e4342598 | 81 | return iReturn; |
wolfSSL | 0:9d17e4342598 | 82 | } |
wolfSSL | 0:9d17e4342598 | 83 | |
wolfSSL | 0:9d17e4342598 | 84 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 85 | { |
wolfSSL | 0:9d17e4342598 | 86 | vSemaphoreDelete( *m ); |
wolfSSL | 0:9d17e4342598 | 87 | return 0; |
wolfSSL | 0:9d17e4342598 | 88 | } |
wolfSSL | 0:9d17e4342598 | 89 | |
wolfSSL | 0:9d17e4342598 | 90 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 91 | { |
wolfSSL | 0:9d17e4342598 | 92 | /* Assume an infinite block, or should there be zero block? */ |
wolfSSL | 0:9d17e4342598 | 93 | xSemaphoreTake( *m, portMAX_DELAY ); |
wolfSSL | 0:9d17e4342598 | 94 | return 0; |
wolfSSL | 0:9d17e4342598 | 95 | } |
wolfSSL | 0:9d17e4342598 | 96 | |
wolfSSL | 0:9d17e4342598 | 97 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 98 | { |
wolfSSL | 0:9d17e4342598 | 99 | xSemaphoreGive( *m ); |
wolfSSL | 0:9d17e4342598 | 100 | return 0; |
wolfSSL | 0:9d17e4342598 | 101 | } |
wolfSSL | 0:9d17e4342598 | 102 | |
wolfSSL | 0:9d17e4342598 | 103 | #elif defined(CYASSL_SAFERTOS) |
wolfSSL | 0:9d17e4342598 | 104 | |
wolfSSL | 0:9d17e4342598 | 105 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 106 | { |
wolfSSL | 0:9d17e4342598 | 107 | vSemaphoreCreateBinary(m->mutexBuffer, m->mutex); |
wolfSSL | 0:9d17e4342598 | 108 | if (m->mutex == NULL) |
wolfSSL | 0:9d17e4342598 | 109 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 110 | |
wolfSSL | 0:9d17e4342598 | 111 | return 0; |
wolfSSL | 0:9d17e4342598 | 112 | } |
wolfSSL | 0:9d17e4342598 | 113 | |
wolfSSL | 0:9d17e4342598 | 114 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 115 | { |
wolfSSL | 0:9d17e4342598 | 116 | (void)m; |
wolfSSL | 0:9d17e4342598 | 117 | return 0; |
wolfSSL | 0:9d17e4342598 | 118 | } |
wolfSSL | 0:9d17e4342598 | 119 | |
wolfSSL | 0:9d17e4342598 | 120 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 121 | { |
wolfSSL | 0:9d17e4342598 | 122 | /* Assume an infinite block */ |
wolfSSL | 0:9d17e4342598 | 123 | xSemaphoreTake(m->mutex, portMAX_DELAY); |
wolfSSL | 0:9d17e4342598 | 124 | return 0; |
wolfSSL | 0:9d17e4342598 | 125 | } |
wolfSSL | 0:9d17e4342598 | 126 | |
wolfSSL | 0:9d17e4342598 | 127 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 128 | { |
wolfSSL | 0:9d17e4342598 | 129 | xSemaphoreGive(m->mutex); |
wolfSSL | 0:9d17e4342598 | 130 | return 0; |
wolfSSL | 0:9d17e4342598 | 131 | } |
wolfSSL | 0:9d17e4342598 | 132 | |
wolfSSL | 0:9d17e4342598 | 133 | |
wolfSSL | 0:9d17e4342598 | 134 | #elif defined(USE_WINDOWS_API) |
wolfSSL | 0:9d17e4342598 | 135 | |
wolfSSL | 0:9d17e4342598 | 136 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 137 | { |
wolfSSL | 0:9d17e4342598 | 138 | InitializeCriticalSection(m); |
wolfSSL | 0:9d17e4342598 | 139 | return 0; |
wolfSSL | 0:9d17e4342598 | 140 | } |
wolfSSL | 0:9d17e4342598 | 141 | |
wolfSSL | 0:9d17e4342598 | 142 | |
wolfSSL | 0:9d17e4342598 | 143 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 144 | { |
wolfSSL | 0:9d17e4342598 | 145 | DeleteCriticalSection(m); |
wolfSSL | 0:9d17e4342598 | 146 | return 0; |
wolfSSL | 0:9d17e4342598 | 147 | } |
wolfSSL | 0:9d17e4342598 | 148 | |
wolfSSL | 0:9d17e4342598 | 149 | |
wolfSSL | 0:9d17e4342598 | 150 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 151 | { |
wolfSSL | 0:9d17e4342598 | 152 | EnterCriticalSection(m); |
wolfSSL | 0:9d17e4342598 | 153 | return 0; |
wolfSSL | 0:9d17e4342598 | 154 | } |
wolfSSL | 0:9d17e4342598 | 155 | |
wolfSSL | 0:9d17e4342598 | 156 | |
wolfSSL | 0:9d17e4342598 | 157 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 158 | { |
wolfSSL | 0:9d17e4342598 | 159 | LeaveCriticalSection(m); |
wolfSSL | 0:9d17e4342598 | 160 | return 0; |
wolfSSL | 0:9d17e4342598 | 161 | } |
wolfSSL | 0:9d17e4342598 | 162 | |
wolfSSL | 0:9d17e4342598 | 163 | #elif defined(CYASSL_PTHREADS) |
wolfSSL | 0:9d17e4342598 | 164 | |
wolfSSL | 0:9d17e4342598 | 165 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 166 | { |
wolfSSL | 0:9d17e4342598 | 167 | if (pthread_mutex_init(m, 0) == 0) |
wolfSSL | 0:9d17e4342598 | 168 | return 0; |
wolfSSL | 0:9d17e4342598 | 169 | else |
wolfSSL | 0:9d17e4342598 | 170 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 171 | } |
wolfSSL | 0:9d17e4342598 | 172 | |
wolfSSL | 0:9d17e4342598 | 173 | |
wolfSSL | 0:9d17e4342598 | 174 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 175 | { |
wolfSSL | 0:9d17e4342598 | 176 | if (pthread_mutex_destroy(m) == 0) |
wolfSSL | 0:9d17e4342598 | 177 | return 0; |
wolfSSL | 0:9d17e4342598 | 178 | else |
wolfSSL | 0:9d17e4342598 | 179 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 180 | } |
wolfSSL | 0:9d17e4342598 | 181 | |
wolfSSL | 0:9d17e4342598 | 182 | |
wolfSSL | 0:9d17e4342598 | 183 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 184 | { |
wolfSSL | 0:9d17e4342598 | 185 | if (pthread_mutex_lock(m) == 0) |
wolfSSL | 0:9d17e4342598 | 186 | return 0; |
wolfSSL | 0:9d17e4342598 | 187 | else |
wolfSSL | 0:9d17e4342598 | 188 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 189 | } |
wolfSSL | 0:9d17e4342598 | 190 | |
wolfSSL | 0:9d17e4342598 | 191 | |
wolfSSL | 0:9d17e4342598 | 192 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 193 | { |
wolfSSL | 0:9d17e4342598 | 194 | if (pthread_mutex_unlock(m) == 0) |
wolfSSL | 0:9d17e4342598 | 195 | return 0; |
wolfSSL | 0:9d17e4342598 | 196 | else |
wolfSSL | 0:9d17e4342598 | 197 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 198 | } |
wolfSSL | 0:9d17e4342598 | 199 | |
wolfSSL | 0:9d17e4342598 | 200 | #elif defined(THREADX) |
wolfSSL | 0:9d17e4342598 | 201 | |
wolfSSL | 0:9d17e4342598 | 202 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 203 | { |
wolfSSL | 0:9d17e4342598 | 204 | if (tx_mutex_create(m, "CyaSSL Mutex", TX_NO_INHERIT) == 0) |
wolfSSL | 0:9d17e4342598 | 205 | return 0; |
wolfSSL | 0:9d17e4342598 | 206 | else |
wolfSSL | 0:9d17e4342598 | 207 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 208 | } |
wolfSSL | 0:9d17e4342598 | 209 | |
wolfSSL | 0:9d17e4342598 | 210 | |
wolfSSL | 0:9d17e4342598 | 211 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 212 | { |
wolfSSL | 0:9d17e4342598 | 213 | if (tx_mutex_delete(m) == 0) |
wolfSSL | 0:9d17e4342598 | 214 | return 0; |
wolfSSL | 0:9d17e4342598 | 215 | else |
wolfSSL | 0:9d17e4342598 | 216 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 217 | } |
wolfSSL | 0:9d17e4342598 | 218 | |
wolfSSL | 0:9d17e4342598 | 219 | |
wolfSSL | 0:9d17e4342598 | 220 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 221 | { |
wolfSSL | 0:9d17e4342598 | 222 | if (tx_mutex_get(m, TX_WAIT_FOREVER) == 0) |
wolfSSL | 0:9d17e4342598 | 223 | return 0; |
wolfSSL | 0:9d17e4342598 | 224 | else |
wolfSSL | 0:9d17e4342598 | 225 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 226 | } |
wolfSSL | 0:9d17e4342598 | 227 | |
wolfSSL | 0:9d17e4342598 | 228 | |
wolfSSL | 0:9d17e4342598 | 229 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 230 | { |
wolfSSL | 0:9d17e4342598 | 231 | if (tx_mutex_put(m) == 0) |
wolfSSL | 0:9d17e4342598 | 232 | return 0; |
wolfSSL | 0:9d17e4342598 | 233 | else |
wolfSSL | 0:9d17e4342598 | 234 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 235 | } |
wolfSSL | 0:9d17e4342598 | 236 | |
wolfSSL | 0:9d17e4342598 | 237 | #elif defined(MICRIUM) |
wolfSSL | 0:9d17e4342598 | 238 | |
wolfSSL | 0:9d17e4342598 | 239 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 240 | { |
wolfSSL | 0:9d17e4342598 | 241 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:9d17e4342598 | 242 | if (NetSecure_OS_MutexCreate(m) == 0) |
wolfSSL | 0:9d17e4342598 | 243 | return 0; |
wolfSSL | 0:9d17e4342598 | 244 | else |
wolfSSL | 0:9d17e4342598 | 245 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 246 | #else |
wolfSSL | 0:9d17e4342598 | 247 | return 0; |
wolfSSL | 0:9d17e4342598 | 248 | #endif |
wolfSSL | 0:9d17e4342598 | 249 | } |
wolfSSL | 0:9d17e4342598 | 250 | |
wolfSSL | 0:9d17e4342598 | 251 | |
wolfSSL | 0:9d17e4342598 | 252 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 253 | { |
wolfSSL | 0:9d17e4342598 | 254 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:9d17e4342598 | 255 | if (NetSecure_OS_FreeMutex(m) == 0) |
wolfSSL | 0:9d17e4342598 | 256 | return 0; |
wolfSSL | 0:9d17e4342598 | 257 | else |
wolfSSL | 0:9d17e4342598 | 258 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 259 | #else |
wolfSSL | 0:9d17e4342598 | 260 | return 0; |
wolfSSL | 0:9d17e4342598 | 261 | #endif |
wolfSSL | 0:9d17e4342598 | 262 | } |
wolfSSL | 0:9d17e4342598 | 263 | |
wolfSSL | 0:9d17e4342598 | 264 | |
wolfSSL | 0:9d17e4342598 | 265 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 266 | { |
wolfSSL | 0:9d17e4342598 | 267 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:9d17e4342598 | 268 | if (NetSecure_OS_LockMutex(m) == 0) |
wolfSSL | 0:9d17e4342598 | 269 | return 0; |
wolfSSL | 0:9d17e4342598 | 270 | else |
wolfSSL | 0:9d17e4342598 | 271 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 272 | #else |
wolfSSL | 0:9d17e4342598 | 273 | return 0; |
wolfSSL | 0:9d17e4342598 | 274 | #endif |
wolfSSL | 0:9d17e4342598 | 275 | } |
wolfSSL | 0:9d17e4342598 | 276 | |
wolfSSL | 0:9d17e4342598 | 277 | |
wolfSSL | 0:9d17e4342598 | 278 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 279 | { |
wolfSSL | 0:9d17e4342598 | 280 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:9d17e4342598 | 281 | if (NetSecure_OS_UnLockMutex(m) == 0) |
wolfSSL | 0:9d17e4342598 | 282 | return 0; |
wolfSSL | 0:9d17e4342598 | 283 | else |
wolfSSL | 0:9d17e4342598 | 284 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 285 | #else |
wolfSSL | 0:9d17e4342598 | 286 | return 0; |
wolfSSL | 0:9d17e4342598 | 287 | #endif |
wolfSSL | 0:9d17e4342598 | 288 | |
wolfSSL | 0:9d17e4342598 | 289 | } |
wolfSSL | 0:9d17e4342598 | 290 | |
wolfSSL | 0:9d17e4342598 | 291 | #elif defined(EBSNET) |
wolfSSL | 0:9d17e4342598 | 292 | |
wolfSSL | 0:9d17e4342598 | 293 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 294 | { |
wolfSSL | 0:9d17e4342598 | 295 | if (rtp_sig_mutex_alloc(m, "CyaSSL Mutex") == -1) |
wolfSSL | 0:9d17e4342598 | 296 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 297 | else |
wolfSSL | 0:9d17e4342598 | 298 | return 0; |
wolfSSL | 0:9d17e4342598 | 299 | } |
wolfSSL | 0:9d17e4342598 | 300 | |
wolfSSL | 0:9d17e4342598 | 301 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 302 | { |
wolfSSL | 0:9d17e4342598 | 303 | rtp_sig_mutex_free(*m); |
wolfSSL | 0:9d17e4342598 | 304 | return 0; |
wolfSSL | 0:9d17e4342598 | 305 | } |
wolfSSL | 0:9d17e4342598 | 306 | |
wolfSSL | 0:9d17e4342598 | 307 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 308 | { |
wolfSSL | 0:9d17e4342598 | 309 | if (rtp_sig_mutex_claim_timed(*m, RTIP_INF) == 0) |
wolfSSL | 0:9d17e4342598 | 310 | return 0; |
wolfSSL | 0:9d17e4342598 | 311 | else |
wolfSSL | 0:9d17e4342598 | 312 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 313 | } |
wolfSSL | 0:9d17e4342598 | 314 | |
wolfSSL | 0:9d17e4342598 | 315 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 316 | { |
wolfSSL | 0:9d17e4342598 | 317 | rtp_sig_mutex_release(*m); |
wolfSSL | 0:9d17e4342598 | 318 | return 0; |
wolfSSL | 0:9d17e4342598 | 319 | } |
wolfSSL | 0:9d17e4342598 | 320 | |
wolfSSL | 0:9d17e4342598 | 321 | #elif defined(FREESCALE_MQX) |
wolfSSL | 0:9d17e4342598 | 322 | |
wolfSSL | 0:9d17e4342598 | 323 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 324 | { |
wolfSSL | 0:9d17e4342598 | 325 | if (_mutex_init(m, NULL) == MQX_EOK) |
wolfSSL | 0:9d17e4342598 | 326 | return 0; |
wolfSSL | 0:9d17e4342598 | 327 | else |
wolfSSL | 0:9d17e4342598 | 328 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 329 | } |
wolfSSL | 0:9d17e4342598 | 330 | |
wolfSSL | 0:9d17e4342598 | 331 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 332 | { |
wolfSSL | 0:9d17e4342598 | 333 | if (_mutex_destroy(m) == MQX_EOK) |
wolfSSL | 0:9d17e4342598 | 334 | return 0; |
wolfSSL | 0:9d17e4342598 | 335 | else |
wolfSSL | 0:9d17e4342598 | 336 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 337 | } |
wolfSSL | 0:9d17e4342598 | 338 | |
wolfSSL | 0:9d17e4342598 | 339 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 340 | { |
wolfSSL | 0:9d17e4342598 | 341 | if (_mutex_lock(m) == MQX_EOK) |
wolfSSL | 0:9d17e4342598 | 342 | return 0; |
wolfSSL | 0:9d17e4342598 | 343 | else |
wolfSSL | 0:9d17e4342598 | 344 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 345 | } |
wolfSSL | 0:9d17e4342598 | 346 | |
wolfSSL | 0:9d17e4342598 | 347 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 348 | { |
wolfSSL | 0:9d17e4342598 | 349 | if (_mutex_unlock(m) == MQX_EOK) |
wolfSSL | 0:9d17e4342598 | 350 | return 0; |
wolfSSL | 0:9d17e4342598 | 351 | else |
wolfSSL | 0:9d17e4342598 | 352 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 353 | } |
wolfSSL | 0:9d17e4342598 | 354 | |
wolfSSL | 0:9d17e4342598 | 355 | #elif defined(CYASSL_MDK_ARM)|| defined(CYASSL_CMSIS_RTOS) |
wolfSSL | 0:9d17e4342598 | 356 | |
wolfSSL | 0:9d17e4342598 | 357 | #if defined(CYASSL_CMSIS_RTOS) |
wolfSSL | 0:9d17e4342598 | 358 | #include "cmsis_os.h" |
wolfSSL | 0:9d17e4342598 | 359 | #define CMSIS_NMUTEX 10 |
wolfSSL | 0:9d17e4342598 | 360 | osMutexDef(CyaSSL_mt0) ; osMutexDef(CyaSSL_mt1) ; osMutexDef(CyaSSL_mt2) ; |
wolfSSL | 0:9d17e4342598 | 361 | osMutexDef(CyaSSL_mt3) ; osMutexDef(CyaSSL_mt4) ; osMutexDef(CyaSSL_mt5) ; |
wolfSSL | 0:9d17e4342598 | 362 | osMutexDef(CyaSSL_mt6) ; osMutexDef(CyaSSL_mt7) ; osMutexDef(CyaSSL_mt8) ; |
wolfSSL | 0:9d17e4342598 | 363 | osMutexDef(CyaSSL_mt9) ; |
wolfSSL | 0:9d17e4342598 | 364 | |
wolfSSL | 0:9d17e4342598 | 365 | static const osMutexDef_t *CMSIS_mutex[] = { osMutex(CyaSSL_mt0), |
wolfSSL | 0:9d17e4342598 | 366 | osMutex(CyaSSL_mt1), osMutex(CyaSSL_mt2), osMutex(CyaSSL_mt3), |
wolfSSL | 0:9d17e4342598 | 367 | osMutex(CyaSSL_mt4), osMutex(CyaSSL_mt5), osMutex(CyaSSL_mt6), |
wolfSSL | 0:9d17e4342598 | 368 | osMutex(CyaSSL_mt7), osMutex(CyaSSL_mt8), osMutex(CyaSSL_mt9) } ; |
wolfSSL | 0:9d17e4342598 | 369 | |
wolfSSL | 0:9d17e4342598 | 370 | static osMutexId CMSIS_mutexID[CMSIS_NMUTEX] = {0} ; |
wolfSSL | 0:9d17e4342598 | 371 | |
wolfSSL | 0:9d17e4342598 | 372 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 373 | { |
wolfSSL | 0:9d17e4342598 | 374 | int i ; |
wolfSSL | 0:9d17e4342598 | 375 | for (i=0; i<CMSIS_NMUTEX; i++) { |
wolfSSL | 0:9d17e4342598 | 376 | if(CMSIS_mutexID[i] == 0) { |
wolfSSL | 0:9d17e4342598 | 377 | CMSIS_mutexID[i] = osMutexCreate(CMSIS_mutex[i]) ; |
wolfSSL | 0:9d17e4342598 | 378 | (*m) = CMSIS_mutexID[i] ; |
wolfSSL | 0:9d17e4342598 | 379 | return 0 ; |
wolfSSL | 0:9d17e4342598 | 380 | } |
wolfSSL | 0:9d17e4342598 | 381 | } |
wolfSSL | 0:9d17e4342598 | 382 | return -1 ; |
wolfSSL | 0:9d17e4342598 | 383 | } |
wolfSSL | 0:9d17e4342598 | 384 | |
wolfSSL | 0:9d17e4342598 | 385 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 386 | { |
wolfSSL | 0:9d17e4342598 | 387 | int i ; |
wolfSSL | 0:9d17e4342598 | 388 | osMutexDelete (*m) ; |
wolfSSL | 0:9d17e4342598 | 389 | for (i=0; i<CMSIS_NMUTEX; i++) { |
wolfSSL | 0:9d17e4342598 | 390 | if(CMSIS_mutexID[i] == (*m)) { |
wolfSSL | 0:9d17e4342598 | 391 | CMSIS_mutexID[i] = 0 ; |
wolfSSL | 0:9d17e4342598 | 392 | return(0) ; |
wolfSSL | 0:9d17e4342598 | 393 | } |
wolfSSL | 0:9d17e4342598 | 394 | } |
wolfSSL | 0:9d17e4342598 | 395 | return(-1) ; |
wolfSSL | 0:9d17e4342598 | 396 | } |
wolfSSL | 0:9d17e4342598 | 397 | |
wolfSSL | 0:9d17e4342598 | 398 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 399 | { |
wolfSSL | 0:9d17e4342598 | 400 | osMutexWait(*m, osWaitForever) ; |
wolfSSL | 0:9d17e4342598 | 401 | return(0) ; |
wolfSSL | 0:9d17e4342598 | 402 | } |
wolfSSL | 0:9d17e4342598 | 403 | |
wolfSSL | 0:9d17e4342598 | 404 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 405 | { |
wolfSSL | 0:9d17e4342598 | 406 | osMutexRelease (*m); |
wolfSSL | 0:9d17e4342598 | 407 | return 0; |
wolfSSL | 0:9d17e4342598 | 408 | } |
wolfSSL | 0:9d17e4342598 | 409 | #else |
wolfSSL | 0:9d17e4342598 | 410 | |
wolfSSL | 0:9d17e4342598 | 411 | int InitMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 412 | { |
wolfSSL | 0:9d17e4342598 | 413 | os_mut_init (m); |
wolfSSL | 0:9d17e4342598 | 414 | return 0; |
wolfSSL | 0:9d17e4342598 | 415 | } |
wolfSSL | 0:9d17e4342598 | 416 | |
wolfSSL | 0:9d17e4342598 | 417 | int FreeMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 418 | { |
wolfSSL | 0:9d17e4342598 | 419 | return(0) ; |
wolfSSL | 0:9d17e4342598 | 420 | } |
wolfSSL | 0:9d17e4342598 | 421 | |
wolfSSL | 0:9d17e4342598 | 422 | int LockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 423 | { |
wolfSSL | 0:9d17e4342598 | 424 | os_mut_wait (m, 0xffff); |
wolfSSL | 0:9d17e4342598 | 425 | return(0) ; |
wolfSSL | 0:9d17e4342598 | 426 | } |
wolfSSL | 0:9d17e4342598 | 427 | |
wolfSSL | 0:9d17e4342598 | 428 | int UnLockMutex(CyaSSL_Mutex* m) |
wolfSSL | 0:9d17e4342598 | 429 | { |
wolfSSL | 0:9d17e4342598 | 430 | os_mut_release (m); |
wolfSSL | 0:9d17e4342598 | 431 | return 0; |
wolfSSL | 0:9d17e4342598 | 432 | } |
wolfSSL | 0:9d17e4342598 | 433 | #endif |
wolfSSL | 0:9d17e4342598 | 434 | #endif /* USE_WINDOWS_API */ |
wolfSSL | 0:9d17e4342598 | 435 | #endif /* SINGLE_THREADED */ |
wolfSSL | 0:9d17e4342598 | 436 |