..

Committer:
ImranBilalButt
Date:
Thu Aug 29 06:43:11 2019 +0000
Revision:
1:a6995e66c9f7
Parent:
0:5f745af3ec9b
..;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ImranBilalButt 0:5f745af3ec9b 1 /*
ImranBilalButt 0:5f745af3ec9b 2 * PackageLicenseDeclared: Apache-2.0
ImranBilalButt 0:5f745af3ec9b 3 * Copyright (c) 2017 ARM Limited
ImranBilalButt 0:5f745af3ec9b 4 *
ImranBilalButt 0:5f745af3ec9b 5 * Licensed under the Apache License, Version 2.0 (the "License");
ImranBilalButt 0:5f745af3ec9b 6 * you may not use this file except in compliance with the License.
ImranBilalButt 0:5f745af3ec9b 7 * You may obtain a copy of the License at
ImranBilalButt 0:5f745af3ec9b 8 *
ImranBilalButt 0:5f745af3ec9b 9 * http://www.apache.org/licenses/LICENSE-2.0
ImranBilalButt 0:5f745af3ec9b 10 *
ImranBilalButt 0:5f745af3ec9b 11 * Unless required by applicable law or agreed to in writing, software
ImranBilalButt 0:5f745af3ec9b 12 * distributed under the License is distributed on an "AS IS" BASIS,
ImranBilalButt 0:5f745af3ec9b 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ImranBilalButt 0:5f745af3ec9b 14 * See the License for the specific language governing permissions and
ImranBilalButt 0:5f745af3ec9b 15 * limitations under the License.
ImranBilalButt 0:5f745af3ec9b 16 */
ImranBilalButt 0:5f745af3ec9b 17
ImranBilalButt 0:5f745af3ec9b 18 #include "TLSSocket.h"
ImranBilalButt 0:5f745af3ec9b 19
ImranBilalButt 0:5f745af3ec9b 20 #define TRACE_GROUP "TLSS"
ImranBilalButt 0:5f745af3ec9b 21 #include "mbed-trace/mbed_trace.h"
ImranBilalButt 0:5f745af3ec9b 22
ImranBilalButt 0:5f745af3ec9b 23
ImranBilalButt 0:5f745af3ec9b 24 /*TLSSocket::SocketAddress getsock() {
ImranBilalButt 0:5f745af3ec9b 25 return sock_addr;
ImranBilalButt 0:5f745af3ec9b 26 }*/
ImranBilalButt 0:5f745af3ec9b 27
ImranBilalButt 0:5f745af3ec9b 28
ImranBilalButt 1:a6995e66c9f7 29 nsapi_error_t TLSSocket::connect1(const char *host, uint16_t port)
ImranBilalButt 0:5f745af3ec9b 30 {
ImranBilalButt 1:a6995e66c9f7 31 pc.printf("[.] Hello from TLSSocket::connect() \n");
ImranBilalButt 1:a6995e66c9f7 32 int ret;
ImranBilalButt 1:a6995e66c9f7 33
ImranBilalButt 1:a6995e66c9f7 34 sock_addr.set_ip_address(host);
ImranBilalButt 1:a6995e66c9f7 35 sock_addr.set_port(port);
ImranBilalButt 1:a6995e66c9f7 36 set_hostname(host);
ImranBilalButt 1:a6995e66c9f7 37
ImranBilalButt 1:a6995e66c9f7 38 return TLSSocketWrapper::connect(sock_addr);
ImranBilalButt 1:a6995e66c9f7 39 }
ImranBilalButt 1:a6995e66c9f7 40
ImranBilalButt 1:a6995e66c9f7 41 nsapi_error_t TLSSocket::connect2(const char *host, uint16_t port)
ImranBilalButt 1:a6995e66c9f7 42 {
ImranBilalButt 1:a6995e66c9f7 43 pc.printf("[.] Hello from TLSSocket::connect() \n");
ImranBilalButt 0:5f745af3ec9b 44 int ret;
ImranBilalButt 0:5f745af3ec9b 45
ImranBilalButt 0:5f745af3ec9b 46 sock_addr.set_ip_address(host);
ImranBilalButt 0:5f745af3ec9b 47 sock_addr.set_port(port);
ImranBilalButt 0:5f745af3ec9b 48 set_hostname(host);
ImranBilalButt 0:5f745af3ec9b 49
ImranBilalButt 0:5f745af3ec9b 50 uint32_t init, final, TCPH, TTPH;
ImranBilalButt 0:5f745af3ec9b 51 init = osKernelGetTickCount();
ImranBilalButt 0:5f745af3ec9b 52 /* Send a 'Client Hello' buffer in order to start a thread on the server */
ImranBilalButt 0:5f745af3ec9b 53 const char* buffer = "Client Hello";
ImranBilalButt 0:5f745af3ec9b 54 if ((ret = udp_socket.sendto(host, port, (const char*) buffer, strlen(buffer))) <= 0)
ImranBilalButt 1:a6995e66c9f7 55 pc.printf("Couldn't send 'Client Hello' \n");
ImranBilalButt 0:5f745af3ec9b 56 else
ImranBilalButt 1:a6995e66c9f7 57 pc.printf("sent 'Client Hello' \n");
ImranBilalButt 0:5f745af3ec9b 58 wait(1);
ImranBilalButt 0:5f745af3ec9b 59 final = osKernelGetTickCount();
ImranBilalButt 0:5f745af3ec9b 60
ImranBilalButt 0:5f745af3ec9b 61 TCPH = final - init;
ImranBilalButt 0:5f745af3ec9b 62 TTPH = TCPH/osKernelGetTickFreq();
ImranBilalButt 0:5f745af3ec9b 63
ImranBilalButt 1:a6995e66c9f7 64 pc.printf("\nTCPH: %d\n", TCPH);
ImranBilalButt 1:a6995e66c9f7 65 pc.printf("\nTTPH: %d\n", TTPH);
ImranBilalButt 1:a6995e66c9f7 66 pc.printf("\nTickFreq: %d\n", osKernelGetTickFreq());
ImranBilalButt 0:5f745af3ec9b 67
ImranBilalButt 0:5f745af3ec9b 68 return TLSSocketWrapper::connect(sock_addr);
ImranBilalButt 1:a6995e66c9f7 69 }