mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*
mbedAustin 11:cada08fc8a70 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
mbedAustin 11:cada08fc8a70 3 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 4 * Licensed under the Apache License, Version 2.0 (the License); you may
mbedAustin 11:cada08fc8a70 5 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 6 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 7 *
mbedAustin 11:cada08fc8a70 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 9 *
mbedAustin 11:cada08fc8a70 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 13 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 14 * limitations under the License.
mbedAustin 11:cada08fc8a70 15 */
mbedAustin 11:cada08fc8a70 16 #ifndef __M2M_CONNECTION_SECURITY_H__
mbedAustin 11:cada08fc8a70 17 #define __M2M_CONNECTION_SECURITY_H__
mbedAustin 11:cada08fc8a70 18
mbedAustin 11:cada08fc8a70 19 class M2MConnectionHandler;
mbedAustin 11:cada08fc8a70 20 class M2MSecurity;
mbedAustin 11:cada08fc8a70 21 class M2MConnectionSecurityPimpl;
mbedAustin 11:cada08fc8a70 22
mbedAustin 11:cada08fc8a70 23 /**
mbedAustin 11:cada08fc8a70 24 * @brief M2MConnectionSecurity.
mbedAustin 11:cada08fc8a70 25 * This class provides a method to create a secure socket connection
mbedAustin 11:cada08fc8a70 26 * to handle connectivity for the mbed Client. It will handle sending, receiving
mbedAustin 11:cada08fc8a70 27 * and establishing a secure connection for the mbed Client on top of the
mbedAustin 11:cada08fc8a70 28 * normal socket connection.
mbedAustin 11:cada08fc8a70 29 */
mbedAustin 11:cada08fc8a70 30
mbedAustin 11:cada08fc8a70 31 class M2MConnectionSecurity {
mbedAustin 11:cada08fc8a70 32 public:
mbedAustin 11:cada08fc8a70 33 typedef enum {
mbedAustin 11:cada08fc8a70 34 NO_SECURITY = 0,
mbedAustin 11:cada08fc8a70 35 TLS,
mbedAustin 11:cada08fc8a70 36 DTLS
mbedAustin 11:cada08fc8a70 37 } SecurityMode;
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 private:
mbedAustin 11:cada08fc8a70 40 // Prevents the use of assignment operator by accident.
mbedAustin 11:cada08fc8a70 41 M2MConnectionSecurity& operator=( const M2MConnectionSecurity& /*other*/ );
mbedAustin 11:cada08fc8a70 42 // Prevents the use of copy constructor by accident.
mbedAustin 11:cada08fc8a70 43 M2MConnectionSecurity( const M2MConnectionSecurity& /*other*/ );
mbedAustin 11:cada08fc8a70 44
mbedAustin 11:cada08fc8a70 45 public:
mbedAustin 11:cada08fc8a70 46 /**
mbedAustin 11:cada08fc8a70 47 * @brief Default Constructor.
mbedAustin 11:cada08fc8a70 48 */
mbedAustin 11:cada08fc8a70 49 M2MConnectionSecurity(SecurityMode mode);
mbedAustin 11:cada08fc8a70 50
mbedAustin 11:cada08fc8a70 51 /**
mbedAustin 11:cada08fc8a70 52 * @brief Default Destructor.
mbedAustin 11:cada08fc8a70 53 */
mbedAustin 11:cada08fc8a70 54 ~M2MConnectionSecurity();
mbedAustin 11:cada08fc8a70 55
mbedAustin 11:cada08fc8a70 56 /**
mbedAustin 11:cada08fc8a70 57 * @brief Resets the socket connection states.
mbedAustin 11:cada08fc8a70 58 */
mbedAustin 11:cada08fc8a70 59 void reset();
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 /**
mbedAustin 11:cada08fc8a70 62 * @brief Initiatlizes the socket connection states.
mbedAustin 11:cada08fc8a70 63 */
mbedAustin 11:cada08fc8a70 64 int init(const M2MSecurity *security);
mbedAustin 11:cada08fc8a70 65
mbedAustin 11:cada08fc8a70 66 /**
mbedAustin 11:cada08fc8a70 67 * @brief Starts the connection in non-blocking mode.
mbedAustin 11:cada08fc8a70 68 * @param connHandler, ConnectionHandler object that maintains the socket.
mbedAustin 11:cada08fc8a70 69 * @return Returns the state of the connection. Successful or not.
mbedAustin 11:cada08fc8a70 70 */
mbedAustin 11:cada08fc8a70 71 int start_connecting_non_blocking(M2MConnectionHandler* connHandler);
mbedAustin 11:cada08fc8a70 72
mbedAustin 11:cada08fc8a70 73 /**
mbedAustin 11:cada08fc8a70 74 * @brief Continues connectivity logic for secure connection.
mbedAustin 11:cada08fc8a70 75 * @return Returns error code if any while continuing connection sequence.
mbedAustin 11:cada08fc8a70 76 */
mbedAustin 11:cada08fc8a70 77 int continue_connecting();
mbedAustin 11:cada08fc8a70 78
mbedAustin 11:cada08fc8a70 79 /**
mbedAustin 11:cada08fc8a70 80 * @brief Connects the client to the server.
mbedAustin 11:cada08fc8a70 81 * @param connHandler, ConnectionHandler object that maintains the socket.
mbedAustin 11:cada08fc8a70 82 * @return Returns the state of the connection. Successful or not.
mbedAustin 11:cada08fc8a70 83 */
mbedAustin 11:cada08fc8a70 84 int connect(M2MConnectionHandler* connHandler);
mbedAustin 11:cada08fc8a70 85
mbedAustin 11:cada08fc8a70 86 /**
mbedAustin 11:cada08fc8a70 87 * @brief Sends data to the server.
mbedAustin 11:cada08fc8a70 88 * @param message, Data to be sent.
mbedAustin 11:cada08fc8a70 89 * @param len, Length of the data.
mbedAustin 11:cada08fc8a70 90 * @return Indicates whether the data is sent successfully or not.
mbedAustin 11:cada08fc8a70 91 */
mbedAustin 11:cada08fc8a70 92 int send_message(unsigned char *message, int len);
mbedAustin 11:cada08fc8a70 93
mbedAustin 11:cada08fc8a70 94 /**
mbedAustin 11:cada08fc8a70 95 * @brief Reads the data received from the server.
mbedAustin 11:cada08fc8a70 96 * @param message, Data to be read.
mbedAustin 11:cada08fc8a70 97 * @param len, Length of the data.
mbedAustin 11:cada08fc8a70 98 * @return Indicates whether the data is read successfully or not.
mbedAustin 11:cada08fc8a70 99 */
mbedAustin 11:cada08fc8a70 100 int read(unsigned char* buffer, uint16_t len);
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 private:
mbedAustin 11:cada08fc8a70 103
mbedAustin 11:cada08fc8a70 104 M2MConnectionSecurityPimpl* _private_impl;
mbedAustin 11:cada08fc8a70 105
mbedAustin 11:cada08fc8a70 106 friend class Test_M2MConnectionSecurity;
mbedAustin 11:cada08fc8a70 107 //friend class Test_M2MConnectionSecurityImpl;
mbedAustin 11:cada08fc8a70 108 };
mbedAustin 11:cada08fc8a70 109
mbedAustin 11:cada08fc8a70 110 #endif //__M2M_CONNECTION_SECURITY_H__