a254ec44f43cacb8fbe510ebc07d68cd171774bc
[platform/upstream/iotivity.git] / resource / csdk / connectivity / samples / arduino / casample.cpp
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #include <ctype.h>
22 #include <errno.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "cacommon.h"
29 #include "cainterface.h"
30 #include "Arduino.h"
31
32 #ifdef ARDUINOWIFI
33 #include "WiFi.h"
34 #elif defined ARDUINOETH
35 #include "Ethernet.h"
36 #endif
37
38 #include "oic_malloc.h"
39
40 #define MAX_BUF_LEN 100 //1024
41 #define MAX_OPT_LEN 16
42 #define PORT_LENGTH 5
43
44 static bool g_isLeSelected = false;
45
46 static void PrintMenu();
47 static void Process();
48 static void Initialize();
49 static void StartListeningServer();
50 static void StartDiscoveryServer();
51 static void SendRequest();
52 static void SendRequestAll();
53 static void SendResponse(CAEndpoint_t *endpoint, const CAInfo_t* info);
54 static void SendNotification();
55 static void SelectNetwork();
56 static void UnselectNetwork();
57 static void HandleRequestResponse();
58 static void GetNetworkInfo();
59
60 static void RequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
61 static void ResponseHandler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
62 static void ErrorHandler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
63 static void Terminate();
64
65 void GetData(char *readInput, size_t bufferLength, size_t *dataLength)
66 {
67     if (!readInput || bufferLength == 0 || !dataLength)
68     {
69         Serial.println("Invalid buffer");
70         return;
71     }
72
73     while (!Serial.available())
74     {
75         delay(500);
76     }
77     int len = 0;
78     while (Serial.available())
79     {
80         delay(100);
81         char c = Serial.read();
82         if ('\n' != c && '\r' != c && len < bufferLength - 1)
83         {
84             readInput[len++] = c;
85         }
86         else
87         {
88             break;
89         }
90     }
91
92     readInput[len] = '\0';
93     Serial.flush();
94     Serial.print("PD: ");
95     Serial.println(readInput);
96     (*dataLength) = len;
97 }
98
99 bool ParseData(char *buf, char *url, char *port, char *resourceUri)
100 {
101     char *slash = strchr(buf, '/');
102     if (!slash)
103     {
104         return false;
105     }
106
107     strcpy(resourceUri, slash);
108
109     char *dot = strchr(buf, '.');
110     if (dot && dot < slash)
111     {
112         char *colon = strchr(buf, ':');
113
114         if (colon)
115         {
116             strncpy(port, colon, slash - colon);
117             memmove(port, port+1, strlen(port));
118         }
119         if (colon && colon < slash)
120         {
121             strncpy(url, buf, colon - buf);
122             return true;
123         }
124     }
125
126     strncpy(url, buf, slash - buf);
127     return true;
128 }
129
130 CATransportAdapter_t GetConnectivityType()
131 {
132     char type[2] = {0};
133     Serial.println("Select network");
134     Serial.println("IP: 0");
135     Serial.println("GATT (BLE): 1");
136     Serial.println("RFCOMM (EDR): 2");
137
138     size_t typeLen = 0;
139     GetData(type, sizeof(type), &typeLen);
140     if (0 >= typeLen)
141     {
142         Serial.println("i/p err,default ethernet");
143         return CA_ADAPTER_IP;
144     }
145     switch (type[0])
146     {
147         case '0':
148             return CA_ADAPTER_IP;
149         case '1':
150             return CA_ADAPTER_GATT_BTLE;
151         case '2':
152             return CA_ADAPTER_RFCOMM_BTEDR;
153     }
154     return CA_ADAPTER_IP;
155 }
156
157 void setup()
158 {
159     Serial.begin (115200);
160
161     Serial.println("============");
162     Serial.println("CA SAMPLE");
163     Serial.println("============");
164     PrintMenu();
165 }
166
167 void loop()
168 {
169     char buffer[5] = {0};
170     size_t len;
171     if (Serial.available() > 0)
172     {
173         GetData(buffer, sizeof(buffer), &len);
174         if (0 >= len)
175         {
176             Serial.println("i/p err");
177             return;
178         }
179         switch (toupper(buffer[0]))
180         {
181             case 'M': // menu
182                 PrintMenu();
183                 break;
184
185             case 'Q': // quit
186                 Serial.println("quit");
187                 return;
188
189             case 'I': // Initialize interface
190                 Initialize();
191                 break;
192
193             case 'S': // start listening server
194                 StartListeningServer();
195                 break;
196
197             case 'D': // start discovery server
198                 StartDiscoveryServer();
199                 break;
200
201             case 'R': // send request
202                 SendRequest();
203                 break;
204
205             case 'E': //send request to all
206                 SendRequestAll();
207                 break;
208             case 'B': // send notification
209                 SendNotification();
210                 break;
211             case 'G': // Get network info
212                 GetNetworkInfo();
213                 break;
214
215             case 'N': // select network
216                 SelectNetwork();
217                 break;
218
219             case 'X': // unselect network
220                 UnselectNetwork();
221                 break;
222
223             case 'H': // handle request response
224                 HandleRequestResponse();
225                 break;
226
227             case 'T': // handle request response
228                 Terminate();
229                 break;
230
231             default:
232                 Serial.println("wrong menu");
233                 break;
234         }
235     }
236     //1:Add check for startserver before calling below api
237     if (g_isLeSelected)
238     {
239         HandleRequestResponse();
240     }
241     delay(1000);
242 }
243
244 void Initialize()
245 {
246     if(CAInitialize() != CA_STATUS_OK)
247     {
248         Serial.println("Initialize failed");
249         return;
250     }
251     SelectNetwork();
252     // set handler.
253     CARegisterHandler(RequestHandler, ResponseHandler, ErrorHandler);
254 }
255
256 void StartListeningServer()
257 {
258     Serial.println("listening server");
259     CAResult_t ret = CAStartListeningServer();
260     if(ret != CA_STATUS_OK)
261     {
262         Serial.print("listening failed: ");
263         Serial.println(ret);
264         return;
265     }
266 }
267
268 void StartDiscoveryServer()
269 {
270     Serial.println("discovery server");
271     CAResult_t ret = CAStartDiscoveryServer();
272     if(ret != CA_STATUS_OK)
273     {
274         Serial.print("discovery failed: ");
275         Serial.println(ret);
276         return;
277     }
278 }
279
280 void SendRequest()
281 {
282     char buf[MAX_BUF_LEN] = {0};
283     char address[MAX_BUF_LEN] = {0};
284     char resourceUri[MAX_BUF_LEN] = {0};
285     char port[PORT_LENGTH] = {0};
286     CATransportAdapter_t selectedNetwork;
287     selectedNetwork = GetConnectivityType();
288
289     Serial.println("============");
290     Serial.println("10.11.12.13:4545/res_uri (for IP)");
291     Serial.println("10:11:12:13:45:45/res_uri (for BT)");
292     Serial.println("uri: ");
293
294     size_t len = 0;
295     GetData(buf, sizeof(buf), &len);
296     if (0 >= len)
297     {
298         Serial.println("i/p err");
299         return;
300     }
301
302     if (!ParseData(buf, address, port, resourceUri))
303     {
304         Serial.println("bad uri");
305         return;
306     }
307
308     // create remote endpoint
309     CAEndpoint_t *endpoint = NULL;
310     CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, atoi(port),
311                                       &endpoint);
312     if (res != CA_STATUS_OK)
313     {
314         Serial.println("Out of memory");
315         CADestroyEndpoint(endpoint);
316         return;
317     }
318
319     memset(buf, 0, sizeof(buf));
320
321     Serial.println("\n=============================================\n");
322     Serial.println("0:CON, 1:NON\n");
323     Serial.println("select message type : ");
324     GetData(buf, sizeof(buf), &len);
325     CAMessageType_t msgType = CA_MSG_CONFIRM;
326
327     if (0 >= len)
328     {
329         Serial.println("i/p err,default: 0");
330     }
331     else if(buf[0] == '1')
332     {
333         msgType = CA_MSG_NONCONFIRM;
334     }
335
336     // create token
337     CAToken_t token = NULL;
338     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
339
340     res = CAGenerateToken(&token, tokenLength);
341     if (res != CA_STATUS_OK || (!token))
342     {
343         Serial.println("token error");
344         return;
345     }
346
347     Serial.println(token);
348     CAInfo_t requestData = {CA_MSG_RESET};
349     requestData.token = token;
350     requestData.tokenLength = tokenLength;
351     requestData.payload = (CAPayload_t)"Json Payload";
352
353     requestData.type = msgType;
354     requestData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
355     strcpy(requestData.resourceUri, resourceUri);
356
357     CARequestInfo_t requestInfo = {CA_GET, {CA_MSG_RESET}};
358     requestInfo.method = CA_GET;
359     requestInfo.isMulticast = false;
360     requestInfo.info = requestData;
361     requestInfo.isMulticast = false;
362
363     // send request
364     CASendRequest(endpoint, &requestInfo);
365     if (NULL != token)
366     {
367         CADestroyToken(token);
368     }
369
370     // destroy remote endpoint
371     if (endpoint != NULL)
372     {
373         CADestroyEndpoint(endpoint);
374     }
375
376     Serial.println("============");
377 }
378
379 void SendRequestAll()
380 {
381     char buf[MAX_BUF_LEN] = {0};
382     char address[MAX_BUF_LEN] = {0};
383     char resourceUri[MAX_BUF_LEN] = {0};
384     char port[PORT_LENGTH] = {0};
385
386     CATransportAdapter_t selectedNetwork;
387     selectedNetwork = GetConnectivityType();
388
389     Serial.println("\n=============================================\n");
390     Serial.println("ex) /a/light\n");
391     Serial.println("resource uri : ");
392
393     size_t len = 0;
394     GetData(buf, sizeof(buf), &len);
395     if (0 >= len)
396     {
397         Serial.println("i/p err");
398         return;
399     }
400
401     if (!ParseData(buf, address, port, resourceUri))
402     {
403         Serial.println("bad uri");
404         return;
405     }
406
407     // create remote endpoint
408     CAEndpoint_t *endpoint = NULL;
409     CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, atoi(port),
410                                         &endpoint);
411
412     if (res != CA_STATUS_OK)
413     {
414         Serial.println("create remote endpoint error");
415         CADestroyEndpoint(endpoint);
416         return;
417     }
418
419     // create token
420     CAToken_t token = NULL;
421     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
422
423     res = CAGenerateToken(&token, tokenLength);
424     if (res != CA_STATUS_OK || (!token))
425     {
426         Serial.println("token error");
427         return;
428     }
429
430     Serial.println(token);
431
432     CAInfo_t requestData = {CA_MSG_RESET};
433     requestData.token = token;
434     requestData.tokenLength = tokenLength;
435     requestData.payload = (CAPayload_t)"Temp Json Payload";
436     requestData.type = CA_MSG_NONCONFIRM;
437     requestData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
438     strcpy(requestData.resourceUri, resourceUri);
439
440     CARequestInfo_t requestInfo = {CA_GET, {CA_MSG_RESET}};
441     requestInfo.method = CA_GET;
442     requestInfo.isMulticast = true;
443     requestInfo.info = requestData;
444
445     // send request
446     CASendRequest(endpoint, &requestInfo);
447
448     if (NULL != token)
449     {
450         CADestroyToken(token);
451     }
452
453     // destroy remote endpoint
454     if (endpoint != NULL)
455     {
456         CADestroyEndpoint(endpoint);
457     }
458
459     Serial.println("==========");
460 }
461
462 void SendNotification()
463 {
464     char buf[MAX_BUF_LEN] = {0};
465     char address[MAX_BUF_LEN] = {0};
466     char resourceUri[MAX_BUF_LEN] = {0};
467     char port[PORT_LENGTH] = {0};
468     CATransportAdapter_t selectedNetwork;
469     selectedNetwork = GetConnectivityType();
470
471     Serial.println("============");
472     Serial.println("10.11.12.13:4545/res_uri (for IP)");
473     Serial.println("10:11:12:13:45:45/res_uri (for BT)");
474     Serial.println("uri: ");
475
476     size_t len = 0;
477     GetData(buf, sizeof(buf), &len);
478     if (0 >= len)
479     {
480         Serial.println("i/p err");
481         return;
482     }
483
484     if (!ParseData(buf, address, port, resourceUri))
485     {
486         Serial.println("bad uri");
487         return;
488     }
489
490     // create remote endpoint
491     CAEndpoint_t *endpoint = NULL;
492     CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, atoi(port),
493                                       &endpoint);
494     if (CA_STATUS_OK != res)
495     {
496         Serial.println("Out of memory");
497         CADestroyEndpoint(endpoint);
498         return;
499     }
500
501     // create token
502     CAToken_t token = NULL;
503     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
504
505     res = CAGenerateToken(&token, tokenLength);
506     if (res != CA_STATUS_OK || (!token))
507     {
508         Serial.println("token error");
509         return;
510     }
511
512     CAInfo_t respondData = {CA_MSG_NONCONFIRM};
513     respondData.token = token;
514     respondData.tokenLength = tokenLength;
515     respondData.payload = (CAPayload_t)"Notification Data";
516     respondData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
517     strcpy(respondData.resourceUri, resourceUri);
518
519     CAResponseInfo_t responseInfo = {CA_BAD_REQ, {CA_MSG_RESET}};
520     responseInfo.result = CA_CONTENT;
521     responseInfo.info = respondData;
522
523     // send request
524     CASendNotification(endpoint, &responseInfo);
525     // destroy remote endpoint
526     if (NULL != endpoint)
527     {
528         CADestroyEndpoint(endpoint);
529     }
530
531     CADestroyToken(token);
532     Serial.println("============");
533 }
534
535 void SelectNetwork()
536 {
537     char buf[MAX_BUF_LEN] = {0};
538
539     Serial.println("============");
540     Serial.println("Select network");
541     Serial.println("IP: 0");
542     Serial.println("LE: 1");
543     Serial.println("EDR: 2\n");
544
545     size_t len = 0;
546     GetData(buf, sizeof(buf), &len);
547     int number = buf[0] - '0';
548     if (0 >= len || number < 0 || number > 3)
549     {
550         Serial.println("Wrong i/p. WIFI selected");
551         number = 1;
552     }
553
554     switch (number)
555     {
556         case 0:
557             {
558 #ifdef ARDUINOWIFI
559                 const char ssid[] = "SSID";              // your network SSID (name)
560                 const char pass[] = "SSID_Password";     // your network password
561                 int16_t status = WL_IDLE_STATUS;         // the Wifi radio's status
562
563                 if (WiFi.status() == WL_NO_SHIELD)
564                 {
565                     Serial.println("ERROR:No Shield");
566                     return;
567                 }
568
569                 while (status != WL_CONNECTED)
570                 {
571                     Serial.print("connecting: ");
572                     Serial.println(ssid);
573                     // WiFi.begin api is weird. ssid should also be taken as const char *
574                     // Connect to WPA/WPA2 network:
575                     status = WiFi.begin((char *)ssid, pass);
576                 }
577 #elif defined ARDUINOETH
578                 // Note: ****Update the MAC address here with your shield's MAC address****
579                 uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x0E, 0xC4, 0x05};
580                 uint8_t error = Ethernet.begin(ETHERNET_MAC);
581                 if (error  == 0)
582                 {
583                     Serial.print("Failed: ");
584                     Serial.println(error);
585                     return;
586                 }
587 #endif
588             }
589             break;
590         case 1:
591             g_isLeSelected = true;
592             break;
593         case 2:
594             // Nothing TBD here
595             break;
596     }
597
598     CASelectNetwork(CATransportAdapter_t(1<<number));
599     Serial.println("============");
600 }
601
602 void UnselectNetwork()
603 {
604     char buf[MAX_BUF_LEN] = {0};
605
606     Serial.println("============");
607     Serial.println("Unselect network");
608     Serial.println("IPv4: 0");
609     Serial.println("LE: 1");
610     Serial.println("EDR: 2\n");
611
612     size_t len = 0;
613     GetData(buf, sizeof(buf), &len);
614     int number = buf[0] - '0';
615     Serial.println(number);
616     if (0 >= len || number < 0 || number > 3)
617     {
618         Serial.println("Wrong i/p. WIFI selected");
619         number = 1;
620     }
621     if (number == 3)
622     {
623         g_isLeSelected = false;
624     }
625     CAUnSelectNetwork(1 << number);
626     Serial.println("Terminate");
627     CATerminate();
628     Serial.println("============");
629 }
630
631 void GetNetworkInfo()
632 {
633     CAEndpoint_t *tempInfo = NULL;
634     uint32_t tempSize = 0;
635     CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
636     if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
637     {
638         Serial.println("Network not connected");
639         free(tempInfo);
640         return;
641     }
642     Serial.println("=========");
643     Serial.print("Network info total size is ");
644     Serial.println(tempSize);
645     int index;
646     for (index = 0; index < tempSize; index++)
647     {
648         Serial.print("Type: ");
649         Serial.println(tempInfo[index].adapter);
650         if (CA_ADAPTER_IP == tempInfo[index].adapter)
651         {
652             Serial.print("Address: ");
653             Serial.println(tempInfo[index].addr);
654             Serial.print("Port: ");
655             Serial.println(tempInfo[index].port);
656         }
657     }
658     free(tempInfo);
659     Serial.println("=======");
660 }
661
662 void PrintMenu()
663 {
664
665     Serial.println("============");
666     Serial.println("i: Initialize");
667     Serial.println("s: start listening server");
668     Serial.println("d: start discovery server");
669     Serial.println("r: send request");
670     Serial.println("e: send request to all");
671     Serial.println("b: send notification");
672     Serial.println("g: get network info");
673     Serial.println("n: select network");
674     Serial.println("x: unselect network");
675     Serial.println("h: handle request response");
676     Serial.println("t: terminate");
677     Serial.println("q: quit");
678     Serial.println("============");
679 }
680
681 void HandleRequestResponse()
682 {
683     CAHandleRequestResponse();
684 }
685
686 void RequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
687 {
688     if (!object)
689     {
690         Serial.println("endpoint is NULL!");
691         return;
692     }
693
694     if (!requestInfo)
695     {
696         Serial.println("Request info is NULL!");
697         return;
698     }
699
700     Serial.print("RAddr: ");
701     Serial.println(object->addr);
702     Serial.print("Port: ");
703     Serial.println(object->port);
704     Serial.print("uri: ");
705     Serial.println(requestInfo->info.resourceUri);
706     Serial.print("data: ");
707     Serial.println((char*)requestInfo->info.payload);
708     Serial.print("Type: ");
709     Serial.println(requestInfo->info.type);
710
711     if (requestInfo->info.options)
712     {
713         uint32_t len = requestInfo->info.numOptions;
714         uint32_t i;
715         for (i = 0; i < len; i++)
716         {
717             Serial.print("Option: ");
718             Serial.println(i+1);
719             Serial.print("ID: ");
720             Serial.println(requestInfo->info.options[i].optionID);
721             Serial.print("Data: ");
722             Serial.println((char*)requestInfo->info.options[i].optionData);
723         }
724     }
725     Serial.println("send response");
726     SendResponse((CAEndpoint_t *)object, (requestInfo != NULL) ? &requestInfo->info : NULL);
727 }
728
729 void ResponseHandler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
730 {
731     if (object)
732     {
733         Serial.print("uri: ");
734         Serial.println(object->addr);
735     }
736
737     if (responseInfo)
738     {
739         Serial.print("uri: ");
740         Serial.println(responseInfo->info.resourceUri);
741         Serial.print("data: ");
742         Serial.println((char*)responseInfo->info.payload);
743         Serial.print("Type: ");
744         Serial.println(responseInfo->info.type);
745         Serial.print("res result=");
746         Serial.println(responseInfo->result);
747     }
748 }
749
750 void ErrorHandler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
751 {
752     Serial.println("ErrorInfo");
753
754     if(errorInfo)
755     {
756         const CAInfo_t *info = &errorInfo->info;
757         Serial.print("result: ");
758         Serial.println(errorInfo->result);
759         Serial.print("token: ");
760         Serial.println(info->token);
761         Serial.print("messageId: ");
762         Serial.println(info->messageId);
763         Serial.print("type: ");
764         Serial.println(info->type);
765         Serial.print("resourceUri: ");
766         Serial.println(info->resourceUri);
767         Serial.print("payload: ");
768         Serial.println((char*)info->payload);
769     }
770
771     return;
772 }
773
774 void SendResponse(CAEndpoint_t *endpoint, const CAInfo_t* info)
775 {
776     char buf[MAX_BUF_LEN] = {0};
777
778     Serial.println("============");
779     Serial.println("Select Message Type");
780     Serial.println("CON: 0");
781     Serial.println("NON: 1");
782     Serial.println("ACK: 2");
783     Serial.println("RESET: 3");
784
785     size_t len = 0;
786     int messageType = 0;
787     while(1)
788     {
789         GetData(buf, sizeof(buf), &len);
790         if(len >= 1)
791         {
792             messageType = buf[0] - '0';
793             if (messageType >= 0 && messageType <= 3)
794             {
795                 break;
796             }
797         }
798         Serial.println("Invalid type");
799     }
800
801     int respCode = 0;
802     if(messageType != 3)
803     {
804         Serial.println("============");
805         Serial.println("Enter Resp Code:");
806         Serial.println("For Ex: Empty  : 0");
807         Serial.println("Success: 200");
808         Serial.println("Created: 201");
809         Serial.println("Deleted: 202");
810         Serial.println("Valid  : 203");
811         Serial.println("Changed: 204");
812         Serial.println("Content: 205");
813         Serial.println("BadReq : 400");
814         Serial.println("BadOpt : 402");
815         Serial.println("NotFnd : 404");
816         Serial.println("Internal Srv Err:500");
817         Serial.println("Timeout: 504");
818         while(1)
819         {
820             GetData(buf, sizeof(buf), &len);
821             if(len >= 1)
822             {
823                 respCode = atoi(buf);
824                 if (respCode >= 0 && respCode <= 504)
825                 {
826                     break;
827                 }
828             }
829             Serial.println("Invalid response");
830         }
831     }
832
833     CAInfo_t responseData = {CA_MSG_RESET};
834     responseData.type = static_cast<CAMessageType_t>(messageType);
835     responseData.messageId = (info != NULL) ? info->messageId : 0;
836     responseData.resourceUri = (info != NULL) ? info->resourceUri : 0;
837     if(messageType != 3)
838     {
839         responseData.token = (info != NULL) ? info->token : NULL;
840         responseData.tokenLength = (info != NULL) ? info->tokenLength : 0;
841         responseData.payload = reinterpret_cast<CAPayload_t>(const_cast<char*>("response payload"));
842     }
843     CAResponseInfo_t responseInfo = {CA_BAD_REQ, {CA_MSG_RESET}};
844     responseInfo.result = static_cast<CAResponseResult_t>(respCode);
845     responseInfo.info = responseData;
846     // send request (transportType from remoteEndpoint of request Info)
847     CAResult_t res = CASendResponse(endpoint, &responseInfo);
848     if(res != CA_STATUS_OK)
849     {
850         Serial.println("Snd Resp error");
851     }
852     else
853     {
854         Serial.println("Snd Resp success");
855     }
856
857     Serial.println("============");
858 }
859
860 void Terminate()
861 {
862     UnselectNetwork();
863 }
864