use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Committer:
ansond
Date:
Fri Mar 04 19:16:57 2016 +0000
Revision:
10:3f79b5e67c22
Parent:
9:faa43faea4ca
Child:
19:56f958475694
updated to allow for specification of UDP or TCP under CoAP and IPv4 or IPv6 addressing types

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 8:f950fb1b78c0 1 /**
ansond 8:f950fb1b78c0 2 * @file Options.cpp
ansond 8:f950fb1b78c0 3 * @brief mbed CoAP Options (immutable OptionsBuilder instance) class implementation
ansond 8:f950fb1b78c0 4 * @author Doug Anson/Chris Paola
ansond 8:f950fb1b78c0 5 * @version 1.0
ansond 8:f950fb1b78c0 6 * @see
ansond 8:f950fb1b78c0 7 *
ansond 8:f950fb1b78c0 8 * Copyright (c) 2014
ansond 8:f950fb1b78c0 9 *
ansond 8:f950fb1b78c0 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 8:f950fb1b78c0 11 * you may not use this file except in compliance with the License.
ansond 8:f950fb1b78c0 12 * You may obtain a copy of the License at
ansond 8:f950fb1b78c0 13 *
ansond 8:f950fb1b78c0 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 8:f950fb1b78c0 15 *
ansond 8:f950fb1b78c0 16 * Unless required by applicable law or agreed to in writing, software
ansond 8:f950fb1b78c0 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 8:f950fb1b78c0 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 8:f950fb1b78c0 19 * See the License for the specific language governing permissions and
ansond 8:f950fb1b78c0 20 * limitations under the License.
ansond 8:f950fb1b78c0 21 */
ansond 8:f950fb1b78c0 22
ansond 8:f950fb1b78c0 23 #include "mbed-connector-interface/Options.h"
ansond 10:3f79b5e67c22 24 #include "mbed-connector-interface/Utils.h"
ansond 8:f950fb1b78c0 25
ansond 8:f950fb1b78c0 26 namespace Connector {
ansond 8:f950fb1b78c0 27
ansond 8:f950fb1b78c0 28 // default constructor
ansond 8:f950fb1b78c0 29 Options::Options()
ansond 8:f950fb1b78c0 30 {
ansond 8:f950fb1b78c0 31 }
ansond 8:f950fb1b78c0 32
ansond 8:f950fb1b78c0 33 // copy constructor
ansond 8:f950fb1b78c0 34 Options::Options(const Options &opt)
ansond 8:f950fb1b78c0 35 {
ansond 8:f950fb1b78c0 36 }
ansond 8:f950fb1b78c0 37
ansond 8:f950fb1b78c0 38 // destructors
ansond 8:f950fb1b78c0 39 Options::~Options()
ansond 8:f950fb1b78c0 40 {
ansond 8:f950fb1b78c0 41 }
ansond 8:f950fb1b78c0 42
ansond 8:f950fb1b78c0 43 // lifetime pointer
ansond 8:f950fb1b78c0 44 int Options::getLifetime()
ansond 8:f950fb1b78c0 45 {
ansond 8:f950fb1b78c0 46 return this->m_lifetime;
ansond 8:f950fb1b78c0 47 }
ansond 8:f950fb1b78c0 48
ansond 8:f950fb1b78c0 49 // NSP domain
ansond 8:f950fb1b78c0 50 string Options::getDomain()
ansond 8:f950fb1b78c0 51 {
ansond 8:f950fb1b78c0 52 return this->m_domain;
ansond 8:f950fb1b78c0 53 }
ansond 8:f950fb1b78c0 54
ansond 8:f950fb1b78c0 55 // Endpoint name
ansond 8:f950fb1b78c0 56 string Options::getEndpointNodename()
ansond 8:f950fb1b78c0 57 {
ansond 8:f950fb1b78c0 58 return this->m_node_name;
ansond 8:f950fb1b78c0 59 }
ansond 8:f950fb1b78c0 60
ansond 8:f950fb1b78c0 61 // Endpoint Type
ansond 8:f950fb1b78c0 62 string Options::getEndpointType()
ansond 8:f950fb1b78c0 63 {
ansond 8:f950fb1b78c0 64 return this->m_endpoint_type;
ansond 8:f950fb1b78c0 65 }
ansond 8:f950fb1b78c0 66
ansond 8:f950fb1b78c0 67 // mbed Registation update period
ansond 8:f950fb1b78c0 68 int Options::getRegUpdatePeriod()
ansond 8:f950fb1b78c0 69 {
ansond 8:f950fb1b78c0 70 return this->m_reg_update_period;
ansond 8:f950fb1b78c0 71 }
ansond 8:f950fb1b78c0 72
ansond 8:f950fb1b78c0 73 // Connector URL
ansond 8:f950fb1b78c0 74 char *Options::getConnectorURL()
ansond 8:f950fb1b78c0 75 {
ansond 8:f950fb1b78c0 76 return (char *)this->m_connector_url.c_str();
ansond 8:f950fb1b78c0 77 }
ansond 0:1f1f55e73248 78
ansond 10:3f79b5e67c22 79 // Connector Port
ansond 10:3f79b5e67c22 80 uint16_t Options::getConnectorPort()
ansond 10:3f79b5e67c22 81 {
ansond 10:3f79b5e67c22 82 return extract_port_from_url(this->getConnectorURL(),DEF_COAP_PORT);
ansond 10:3f79b5e67c22 83 }
ansond 10:3f79b5e67c22 84
ansond 8:f950fb1b78c0 85 // Device Resources
ansond 8:f950fb1b78c0 86 DeviceResourcesList *Options::getDeviceResourceList()
ansond 8:f950fb1b78c0 87 {
ansond 8:f950fb1b78c0 88 return &this->m_device_resources;
ansond 8:f950fb1b78c0 89 }
ansond 8:f950fb1b78c0 90
ansond 8:f950fb1b78c0 91 // Static Resources
ansond 8:f950fb1b78c0 92 StaticResourcesList *Options::getStaticResourceList()
ansond 8:f950fb1b78c0 93 {
ansond 8:f950fb1b78c0 94 return &this->m_static_resources;
ansond 8:f950fb1b78c0 95 }
ansond 8:f950fb1b78c0 96
ansond 8:f950fb1b78c0 97 // Dynamic Resources
ansond 8:f950fb1b78c0 98 DynamicResourcesList *Options::getDynamicResourceList()
ansond 8:f950fb1b78c0 99 {
ansond 8:f950fb1b78c0 100 return &this->m_dynamic_resources;
ansond 8:f950fb1b78c0 101 }
ansond 8:f950fb1b78c0 102
ansond 8:f950fb1b78c0 103 // WiFi SSID
ansond 8:f950fb1b78c0 104 string Options::getWiFiSSID() {
ansond 8:f950fb1b78c0 105 return this->m_wifi_ssid;
ansond 8:f950fb1b78c0 106 }
ansond 8:f950fb1b78c0 107
ansond 8:f950fb1b78c0 108 // WiFi AuthType
ansond 8:f950fb1b78c0 109 WiFiAuthTypes Options::getWiFiAuthType() {
ansond 8:f950fb1b78c0 110 return this->m_wifi_auth_type;
ansond 8:f950fb1b78c0 111 }
ansond 8:f950fb1b78c0 112
ansond 8:f950fb1b78c0 113 // WiFi AuthKey
ansond 8:f950fb1b78c0 114 string Options::getWiFiAuthKey() {
ansond 8:f950fb1b78c0 115 return this->m_wifi_auth_key;
ansond 8:f950fb1b78c0 116 }
ansond 8:f950fb1b78c0 117
ansond 8:f950fb1b78c0 118 // 802.15.4 Pre Shared Key
ansond 8:f950fb1b78c0 119 unsigned char *Options::getPreSharedKey() {
ansond 8:f950fb1b78c0 120 return this->m_psk;
ansond 8:f950fb1b78c0 121 }
ansond 8:f950fb1b78c0 122
ansond 8:f950fb1b78c0 123 // 802.15.4 Pre Shared Key Identity
ansond 8:f950fb1b78c0 124 unsigned char *Options::getPreSharedKeyIdentity() {
ansond 8:f950fb1b78c0 125 return this->m_psk_identity;
ansond 8:f950fb1b78c0 126 }
ansond 8:f950fb1b78c0 127
ansond 9:faa43faea4ca 128 // 802.15.4 Mesh Type
ansond 9:faa43faea4ca 129 MeshTypes Options::getMeshType() {
ansond 9:faa43faea4ca 130 return this->m_mesh_type;
ansond 9:faa43faea4ca 131 }
ansond 9:faa43faea4ca 132
ansond 10:3f79b5e67c22 133 // CoAP Connection Type
ansond 10:3f79b5e67c22 134 CoAPConnectionTypes Options::getCoAPConnectionType() {
ansond 10:3f79b5e67c22 135 return this->m_coap_connection_type;
ansond 10:3f79b5e67c22 136 }
ansond 10:3f79b5e67c22 137
ansond 10:3f79b5e67c22 138 // IP Address Type
ansond 10:3f79b5e67c22 139 IPAddressTypes Options::getIPAddressType() {
ansond 10:3f79b5e67c22 140 return this->m_ip_address_type;
ansond 10:3f79b5e67c22 141 }
ansond 10:3f79b5e67c22 142
ansond 8:f950fb1b78c0 143 // Immediate Observationing Enabled
ansond 8:f950fb1b78c0 144 bool Options::immedateObservationEnabled() {
ansond 8:f950fb1b78c0 145 return this->m_enable_immediate_observation;
ansond 8:f950fb1b78c0 146 }
ansond 8:f950fb1b78c0 147
ansond 8:f950fb1b78c0 148 // Enable/Disable Observation control via GET
ansond 8:f950fb1b78c0 149 bool Options::enableGETObservationControl() {
ansond 8:f950fb1b78c0 150 return this->m_enable_get_obs_control;
ansond 8:f950fb1b78c0 151 }
ansond 8:f950fb1b78c0 152
ansond 8:f950fb1b78c0 153 // Get the Server Certificate
ansond 8:f950fb1b78c0 154 uint8_t *Options::getServerCertificate() {
ansond 8:f950fb1b78c0 155 return (uint8_t *) this->m_server_cert;
ansond 8:f950fb1b78c0 156 }
ansond 8:f950fb1b78c0 157
ansond 8:f950fb1b78c0 158 // Get the Server Certificate length
ansond 8:f950fb1b78c0 159 int Options::getServerCertificateSize() {
ansond 8:f950fb1b78c0 160 return this->m_server_cert_length;
ansond 8:f950fb1b78c0 161 }
ansond 8:f950fb1b78c0 162
ansond 8:f950fb1b78c0 163 // Get the Client Certificate
ansond 8:f950fb1b78c0 164 uint8_t *Options::getClientCertificate() {
ansond 8:f950fb1b78c0 165 return (uint8_t *) this->m_client_cert;
ansond 8:f950fb1b78c0 166 }
ansond 8:f950fb1b78c0 167
ansond 8:f950fb1b78c0 168 // Get the Client Certificate length
ansond 8:f950fb1b78c0 169 int Options::getClientCertificateSize() {
ansond 8:f950fb1b78c0 170 return this->m_client_cert_length;
ansond 8:f950fb1b78c0 171 }
ansond 8:f950fb1b78c0 172
ansond 8:f950fb1b78c0 173 // Get the Client Key
ansond 8:f950fb1b78c0 174 uint8_t *Options::getClientKey() {
ansond 8:f950fb1b78c0 175 return (uint8_t *) this->m_client_key;
ansond 8:f950fb1b78c0 176 }
ansond 8:f950fb1b78c0 177
ansond 8:f950fb1b78c0 178 // Get the Client Key length
ansond 8:f950fb1b78c0 179 int Options::getClientKeySize() {
ansond 8:f950fb1b78c0 180 return this->m_client_key_length;
ansond 8:f950fb1b78c0 181 }
ansond 8:f950fb1b78c0 182
ansond 8:f950fb1b78c0 183 } // namespace Connector