The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

See the WNCInterface README in the Wiki tab for detailed information on this library.

Committer:
JMF
Date:
Fri Mar 24 22:26:23 2017 +0000
Revision:
29:b278b745fb4f
Parent:
12:0071cb144c7a
updated Class name of TCPSocketConnection to WncTCPSocketConnection;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /*
JMF 12:0071cb144c7a 2 * Threading abstraction layer
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 5 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 6 *
JMF 12:0071cb144c7a 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 8 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 9 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 10 *
JMF 12:0071cb144c7a 11 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 16 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 17 * limitations under the License.
JMF 12:0071cb144c7a 18 *
JMF 12:0071cb144c7a 19 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 20 */
JMF 12:0071cb144c7a 21
JMF 12:0071cb144c7a 22 #if !defined(MBEDTLS_CONFIG_FILE)
JMF 12:0071cb144c7a 23 #include "mbedtls/config.h"
JMF 12:0071cb144c7a 24 #else
JMF 12:0071cb144c7a 25 #include MBEDTLS_CONFIG_FILE
JMF 12:0071cb144c7a 26 #endif
JMF 12:0071cb144c7a 27
JMF 12:0071cb144c7a 28 #if defined(MBEDTLS_THREADING_C)
JMF 12:0071cb144c7a 29
JMF 12:0071cb144c7a 30 #include "mbedtls/threading.h"
JMF 12:0071cb144c7a 31
JMF 12:0071cb144c7a 32 #if defined(MBEDTLS_THREADING_PTHREAD)
JMF 12:0071cb144c7a 33 static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 34 {
JMF 12:0071cb144c7a 35 if( mutex == NULL )
JMF 12:0071cb144c7a 36 return;
JMF 12:0071cb144c7a 37
JMF 12:0071cb144c7a 38 mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0;
JMF 12:0071cb144c7a 39 }
JMF 12:0071cb144c7a 40
JMF 12:0071cb144c7a 41 static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 42 {
JMF 12:0071cb144c7a 43 if( mutex == NULL )
JMF 12:0071cb144c7a 44 return;
JMF 12:0071cb144c7a 45
JMF 12:0071cb144c7a 46 (void) pthread_mutex_destroy( &mutex->mutex );
JMF 12:0071cb144c7a 47 }
JMF 12:0071cb144c7a 48
JMF 12:0071cb144c7a 49 static int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 50 {
JMF 12:0071cb144c7a 51 if( mutex == NULL || ! mutex->is_valid )
JMF 12:0071cb144c7a 52 return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
JMF 12:0071cb144c7a 53
JMF 12:0071cb144c7a 54 if( pthread_mutex_lock( &mutex->mutex ) != 0 )
JMF 12:0071cb144c7a 55 return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
JMF 12:0071cb144c7a 56
JMF 12:0071cb144c7a 57 return( 0 );
JMF 12:0071cb144c7a 58 }
JMF 12:0071cb144c7a 59
JMF 12:0071cb144c7a 60 static int threading_mutex_unlock_pthread( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 61 {
JMF 12:0071cb144c7a 62 if( mutex == NULL || ! mutex->is_valid )
JMF 12:0071cb144c7a 63 return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
JMF 12:0071cb144c7a 64
JMF 12:0071cb144c7a 65 if( pthread_mutex_unlock( &mutex->mutex ) != 0 )
JMF 12:0071cb144c7a 66 return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
JMF 12:0071cb144c7a 67
JMF 12:0071cb144c7a 68 return( 0 );
JMF 12:0071cb144c7a 69 }
JMF 12:0071cb144c7a 70
JMF 12:0071cb144c7a 71 void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_init_pthread;
JMF 12:0071cb144c7a 72 void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_free_pthread;
JMF 12:0071cb144c7a 73 int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_lock_pthread;
JMF 12:0071cb144c7a 74 int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_unlock_pthread;
JMF 12:0071cb144c7a 75
JMF 12:0071cb144c7a 76 /*
JMF 12:0071cb144c7a 77 * With phtreads we can statically initialize mutexes
JMF 12:0071cb144c7a 78 */
JMF 12:0071cb144c7a 79 #define MUTEX_INIT = { PTHREAD_MUTEX_INITIALIZER, 1 }
JMF 12:0071cb144c7a 80
JMF 12:0071cb144c7a 81 #endif /* MBEDTLS_THREADING_PTHREAD */
JMF 12:0071cb144c7a 82
JMF 12:0071cb144c7a 83 #if defined(MBEDTLS_THREADING_ALT)
JMF 12:0071cb144c7a 84 static int threading_mutex_fail( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 85 {
JMF 12:0071cb144c7a 86 ((void) mutex );
JMF 12:0071cb144c7a 87 return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
JMF 12:0071cb144c7a 88 }
JMF 12:0071cb144c7a 89 static void threading_mutex_dummy( mbedtls_threading_mutex_t *mutex )
JMF 12:0071cb144c7a 90 {
JMF 12:0071cb144c7a 91 ((void) mutex );
JMF 12:0071cb144c7a 92 return;
JMF 12:0071cb144c7a 93 }
JMF 12:0071cb144c7a 94
JMF 12:0071cb144c7a 95 void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy;
JMF 12:0071cb144c7a 96 void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy;
JMF 12:0071cb144c7a 97 int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail;
JMF 12:0071cb144c7a 98 int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail;
JMF 12:0071cb144c7a 99
JMF 12:0071cb144c7a 100 /*
JMF 12:0071cb144c7a 101 * Set functions pointers and initialize global mutexes
JMF 12:0071cb144c7a 102 */
JMF 12:0071cb144c7a 103 void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
JMF 12:0071cb144c7a 104 void (*mutex_free)( mbedtls_threading_mutex_t * ),
JMF 12:0071cb144c7a 105 int (*mutex_lock)( mbedtls_threading_mutex_t * ),
JMF 12:0071cb144c7a 106 int (*mutex_unlock)( mbedtls_threading_mutex_t * ) )
JMF 12:0071cb144c7a 107 {
JMF 12:0071cb144c7a 108 mbedtls_mutex_init = mutex_init;
JMF 12:0071cb144c7a 109 mbedtls_mutex_free = mutex_free;
JMF 12:0071cb144c7a 110 mbedtls_mutex_lock = mutex_lock;
JMF 12:0071cb144c7a 111 mbedtls_mutex_unlock = mutex_unlock;
JMF 12:0071cb144c7a 112
JMF 12:0071cb144c7a 113 mbedtls_mutex_init( &mbedtls_threading_readdir_mutex );
JMF 12:0071cb144c7a 114 mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex );
JMF 12:0071cb144c7a 115 }
JMF 12:0071cb144c7a 116
JMF 12:0071cb144c7a 117 /*
JMF 12:0071cb144c7a 118 * Free global mutexes
JMF 12:0071cb144c7a 119 */
JMF 12:0071cb144c7a 120 void mbedtls_threading_free_alt( void )
JMF 12:0071cb144c7a 121 {
JMF 12:0071cb144c7a 122 mbedtls_mutex_free( &mbedtls_threading_readdir_mutex );
JMF 12:0071cb144c7a 123 mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex );
JMF 12:0071cb144c7a 124 }
JMF 12:0071cb144c7a 125 #endif /* MBEDTLS_THREADING_ALT */
JMF 12:0071cb144c7a 126
JMF 12:0071cb144c7a 127 /*
JMF 12:0071cb144c7a 128 * Define global mutexes
JMF 12:0071cb144c7a 129 */
JMF 12:0071cb144c7a 130 #ifndef MUTEX_INIT
JMF 12:0071cb144c7a 131 #define MUTEX_INIT
JMF 12:0071cb144c7a 132 #endif
JMF 12:0071cb144c7a 133 mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT;
JMF 12:0071cb144c7a 134 mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT;
JMF 12:0071cb144c7a 135
JMF 12:0071cb144c7a 136 #endif /* MBEDTLS_THREADING_C */