cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:54:58 2013 +0000
Revision:
0:e979170e02e7
Basic operation of SSL with PSK working for cellular.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* logging.c
ashleymills 0:e979170e02e7 2 *
ashleymills 0:e979170e02e7 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
ashleymills 0:e979170e02e7 4 *
ashleymills 0:e979170e02e7 5 * This file is part of CyaSSL.
ashleymills 0:e979170e02e7 6 *
ashleymills 0:e979170e02e7 7 * CyaSSL is free software; you can redistribute it and/or modify
ashleymills 0:e979170e02e7 8 * it under the terms of the GNU General Public License as published by
ashleymills 0:e979170e02e7 9 * the Free Software Foundation; either version 2 of the License, or
ashleymills 0:e979170e02e7 10 * (at your option) any later version.
ashleymills 0:e979170e02e7 11 *
ashleymills 0:e979170e02e7 12 * CyaSSL is distributed in the hope that it will be useful,
ashleymills 0:e979170e02e7 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ashleymills 0:e979170e02e7 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ashleymills 0:e979170e02e7 15 * GNU General Public License for more details.
ashleymills 0:e979170e02e7 16 *
ashleymills 0:e979170e02e7 17 * You should have received a copy of the GNU General Public License
ashleymills 0:e979170e02e7 18 * along with this program; if not, write to the Free Software
ashleymills 0:e979170e02e7 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ashleymills 0:e979170e02e7 20 */
ashleymills 0:e979170e02e7 21
ashleymills 0:e979170e02e7 22 #define DEBUG_CYASSL
ashleymills 0:e979170e02e7 23
ashleymills 0:e979170e02e7 24 #ifdef HAVE_CONFIG_H
ashleymills 0:e979170e02e7 25 #include <config.h>
ashleymills 0:e979170e02e7 26 #endif
ashleymills 0:e979170e02e7 27
ashleymills 0:e979170e02e7 28 /* submitted by eof */
ashleymills 0:e979170e02e7 29
ashleymills 0:e979170e02e7 30 #include <cyassl/ctaocrypt/settings.h>
ashleymills 0:e979170e02e7 31 #include <cyassl/ctaocrypt/logging.h>
ashleymills 0:e979170e02e7 32 #include <cyassl/ctaocrypt/error.h>
ashleymills 0:e979170e02e7 33
ashleymills 0:e979170e02e7 34
ashleymills 0:e979170e02e7 35 #ifdef __cplusplus
ashleymills 0:e979170e02e7 36 extern "C" {
ashleymills 0:e979170e02e7 37 #endif
ashleymills 0:e979170e02e7 38 CYASSL_API int CyaSSL_Debugging_ON(void);
ashleymills 0:e979170e02e7 39 CYASSL_API void CyaSSL_Debugging_OFF(void);
ashleymills 0:e979170e02e7 40 #ifdef __cplusplus
ashleymills 0:e979170e02e7 41 }
ashleymills 0:e979170e02e7 42 #endif
ashleymills 0:e979170e02e7 43
ashleymills 0:e979170e02e7 44
ashleymills 0:e979170e02e7 45 #ifdef DEBUG_CYASSL
ashleymills 0:e979170e02e7 46
ashleymills 0:e979170e02e7 47 /* Set these to default values initially. */
ashleymills 0:e979170e02e7 48 static CyaSSL_Logging_cb log_function = 0;
ashleymills 0:e979170e02e7 49 static int loggingEnabled = 0;
ashleymills 0:e979170e02e7 50
ashleymills 0:e979170e02e7 51 #endif /* DEBUG_CYASSL */
ashleymills 0:e979170e02e7 52
ashleymills 0:e979170e02e7 53
ashleymills 0:e979170e02e7 54 int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
ashleymills 0:e979170e02e7 55 {
ashleymills 0:e979170e02e7 56 #ifdef DEBUG_CYASSL
ashleymills 0:e979170e02e7 57 int res = 0;
ashleymills 0:e979170e02e7 58
ashleymills 0:e979170e02e7 59 if (f)
ashleymills 0:e979170e02e7 60 log_function = f;
ashleymills 0:e979170e02e7 61 else
ashleymills 0:e979170e02e7 62 res = BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 63
ashleymills 0:e979170e02e7 64 return res;
ashleymills 0:e979170e02e7 65 #else
ashleymills 0:e979170e02e7 66 (void)f;
ashleymills 0:e979170e02e7 67 return NOT_COMPILED_IN;
ashleymills 0:e979170e02e7 68 #endif
ashleymills 0:e979170e02e7 69 }
ashleymills 0:e979170e02e7 70
ashleymills 0:e979170e02e7 71
ashleymills 0:e979170e02e7 72 int CyaSSL_Debugging_ON(void)
ashleymills 0:e979170e02e7 73 {
ashleymills 0:e979170e02e7 74
ashleymills 0:e979170e02e7 75 #ifdef DEBUG_CYASSL
ashleymills 0:e979170e02e7 76 loggingEnabled = 1;
ashleymills 0:e979170e02e7 77 return 0;
ashleymills 0:e979170e02e7 78 #else
ashleymills 0:e979170e02e7 79 return NOT_COMPILED_IN;
ashleymills 0:e979170e02e7 80 #endif
ashleymills 0:e979170e02e7 81 }
ashleymills 0:e979170e02e7 82
ashleymills 0:e979170e02e7 83
ashleymills 0:e979170e02e7 84 void CyaSSL_Debugging_OFF(void)
ashleymills 0:e979170e02e7 85 {
ashleymills 0:e979170e02e7 86 #ifdef DEBUG_CYASSL
ashleymills 0:e979170e02e7 87 loggingEnabled = 0;
ashleymills 0:e979170e02e7 88 #endif
ashleymills 0:e979170e02e7 89 }
ashleymills 0:e979170e02e7 90
ashleymills 0:e979170e02e7 91
ashleymills 0:e979170e02e7 92 #ifdef DEBUG_CYASSL
ashleymills 0:e979170e02e7 93
ashleymills 0:e979170e02e7 94 #ifdef FREESCALE_MQX
ashleymills 0:e979170e02e7 95 #include <fio.h>
ashleymills 0:e979170e02e7 96 #else
ashleymills 0:e979170e02e7 97 #include <stdio.h> /* for default printf stuff */
ashleymills 0:e979170e02e7 98 #endif
ashleymills 0:e979170e02e7 99
ashleymills 0:e979170e02e7 100 #ifdef THREADX
ashleymills 0:e979170e02e7 101 int dc_log_printf(char*, ...);
ashleymills 0:e979170e02e7 102 #endif
ashleymills 0:e979170e02e7 103
ashleymills 0:e979170e02e7 104 static void cyassl_log(const int logLevel, const char *const logMessage)
ashleymills 0:e979170e02e7 105 {
ashleymills 0:e979170e02e7 106 if (log_function)
ashleymills 0:e979170e02e7 107 log_function(logLevel, logMessage);
ashleymills 0:e979170e02e7 108 else {
ashleymills 0:e979170e02e7 109 if (loggingEnabled) {
ashleymills 0:e979170e02e7 110 #ifdef THREADX
ashleymills 0:e979170e02e7 111 dc_log_printf("%s\n", logMessage);
ashleymills 0:e979170e02e7 112 #elif defined(MICRIUM)
ashleymills 0:e979170e02e7 113 #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
ashleymills 0:e979170e02e7 114 NetSecure_TraceOut((CPU_CHAR *)logMessage);
ashleymills 0:e979170e02e7 115 #endif
ashleymills 0:e979170e02e7 116 #else
ashleymills 0:e979170e02e7 117 //fprintf(stderr, "%s\n", logMessage);
ashleymills 0:e979170e02e7 118 printf("%s\r\n",logMessage);
ashleymills 0:e979170e02e7 119 #endif
ashleymills 0:e979170e02e7 120 }
ashleymills 0:e979170e02e7 121 }
ashleymills 0:e979170e02e7 122 }
ashleymills 0:e979170e02e7 123
ashleymills 0:e979170e02e7 124
ashleymills 0:e979170e02e7 125 void CYASSL_MSG(const char* msg)
ashleymills 0:e979170e02e7 126 {
ashleymills 0:e979170e02e7 127 if (loggingEnabled)
ashleymills 0:e979170e02e7 128 cyassl_log(INFO_LOG , msg);
ashleymills 0:e979170e02e7 129 }
ashleymills 0:e979170e02e7 130
ashleymills 0:e979170e02e7 131
ashleymills 0:e979170e02e7 132 void CYASSL_ENTER(const char* msg)
ashleymills 0:e979170e02e7 133 {
ashleymills 0:e979170e02e7 134 if (loggingEnabled) {
ashleymills 0:e979170e02e7 135 char buffer[80];
ashleymills 0:e979170e02e7 136 sprintf(buffer, "CyaSSL Entering %s", msg);
ashleymills 0:e979170e02e7 137 cyassl_log(ENTER_LOG , buffer);
ashleymills 0:e979170e02e7 138 }
ashleymills 0:e979170e02e7 139 }
ashleymills 0:e979170e02e7 140
ashleymills 0:e979170e02e7 141
ashleymills 0:e979170e02e7 142 void CYASSL_LEAVE(const char* msg, int ret)
ashleymills 0:e979170e02e7 143 {
ashleymills 0:e979170e02e7 144 if (loggingEnabled) {
ashleymills 0:e979170e02e7 145 char buffer[80];
ashleymills 0:e979170e02e7 146 sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
ashleymills 0:e979170e02e7 147 cyassl_log(LEAVE_LOG , buffer);
ashleymills 0:e979170e02e7 148 }
ashleymills 0:e979170e02e7 149 }
ashleymills 0:e979170e02e7 150
ashleymills 0:e979170e02e7 151
ashleymills 0:e979170e02e7 152 void CYASSL_ERROR(int error)
ashleymills 0:e979170e02e7 153 {
ashleymills 0:e979170e02e7 154 if (loggingEnabled) {
ashleymills 0:e979170e02e7 155 char buffer[80];
ashleymills 0:e979170e02e7 156 sprintf(buffer, "CyaSSL error occured, error = %d", error);
ashleymills 0:e979170e02e7 157 cyassl_log(ERROR_LOG , buffer);
ashleymills 0:e979170e02e7 158 }
ashleymills 0:e979170e02e7 159 }
ashleymills 0:e979170e02e7 160
ashleymills 0:e979170e02e7 161 #endif /* DEBUG_CYASSL */