NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
CoAP.h
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Siddharth Makadia *
12* *
13* ---------------------------------------------------------------------------------*/
14
15#include "main.h"
16#include "Stack.h"
17
18//CoAP Derived Protocol Parameters default values (in seconds)
19#define MAX_TRANSMIT_SPAN 45
20#define MAX_TRANSMIT_WAIT 93
21#define MAX_LATENCY 100
22#define PROCESSING_DELAY 2
23#define MAX_RTT 202
24#define EXCHANGE_LIFETIME 427
25#define NON_LIFETIME 145
26
27
28#define MESSAGE_SIZE_UPPER_BOUND 1152 //BYTES
29#define PAYLOAD_SIZE_UPPER_BOUND 1152 //BYTES
30typedef struct stru_NetSim_COAP_Header COAP_Header;
31typedef struct stru_NetSim_COAP_Options COAP_Options;
32
33typedef struct stru_NetSim_COAP_data COAP_Data;
34
35
36/*
37A summary of the contents of the CoAP header as per RFC 7252 follows:
38
39 0 1 2 3
40 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 |Ver| T | TKL | Code | Message ID |
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 | Token (if any, TKL bytes) ...
45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 | Options (if any) ...
47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 |1 1 1 1 1 1 1 1| Payload (if any) ...
49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50
51*/
52
53typedef enum
54{
55 CONFIRMABLE,
56 NON_CONFIRMABLE,
57 ACKNOWLEDGEMENT,
58 RESET,
59}COAP_TYPE;
60
61typedef enum
62{
63 REQUEST = 0,
64 RESPONSE = 2,
65 CLIENT_ERROR = 4,
66 SERVER_ERROR = 5,
67}COAP_CODE;
69
70 unsigned int Request_messageID;
71 unsigned int Request_tokenValue;
72 unsigned int Response_messageID;
73 unsigned int Response_tokenValue;
74
75 unsigned int Response_Received;
76 unsigned int RequestACK_Received;
77 unsigned int Request_Received;
78 unsigned int ResponseACK_Received;
79
80 int _RETRANSMIT;
81 int _gz;
82
83};
85 unsigned int optionDelta : 4;
86 unsigned int optionLength : 4;
87 void* optionvalue;
88};
90{
91 unsigned int Version : 2; // always 1
92 unsigned int Type : 2; // Confirmable (0), Non-confirmable (1), Acknowledgement (2), or Reset(3)
93 unsigned int TokenLength : 4; //length of tokenvalue field in bytes
94 unsigned int Code : 8; // request (0) , success response (2) , client error response (4) , server error response(5)
95 unsigned int MessageID : 16; //must be match for request and response ACK
96 unsigned int tokenvalue : 32; //must be a match for request and response message
97 struct stru_NetSim_COAP_Options* Options;
98
99};
100
101
102COAP_Header* fn_NetSim_Application_COAP_GenrateHeader(APP_COAP_INFO* info);
103
104void fn_NetSim_Application_COAP_AppIn(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
105
106int fn_NetSim_Application_COAP_Start(ptrAPPLICATION_INFO appInfo, NetSim_EVENTDETAILS* pstruEventDetails);
107int fn_NetSim_Application_StartCOAPAPP(ptrAPPLICATION_INFO appInfo, double time);
108int fn_NetSim_Application_COAP_ProcessRequest(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
109int fn_NetSim_Application_COAP_Sent_ACK(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
110int fn_NetSim_Application_COAP_Genrate_RequestPacket(ptrAPPLICATION_INFO appInfo, NETSIM_ID nSource, NETSIM_ID nDestination, double time, char* PacketType);
111int fn_NetSim_Application_COAP_Genrate_Packet(ptrAPPLICATION_INFO pstruappinfo, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double size, char* PacketType);
112COAP_Header* fn_NetSim_Application_COAP_CopyHeader(COAP_Header* src);