Friendly LWM2M client
Lwm2mSecurity.cpp
Go to the documentation of this file.
1 /*
2  * Lwm2mSecurity
3  * Generated on: 2023-11-02 16:43:32
4  * Created by: Sinai RnD
5  */
6 
8 
9 #include "Resource.h"
10 #include "ItemOp.h"
11 #include "WppTypes.h"
12 #include "WppLogs.h"
13 #include "WppClient.h"
14 
15 /* --------------- Code_cpp block 0 start --------------- */
16 #define SERVER_URI_MAX_SIZE 255
17 #if RES_0_7
18 #define SMS_BIND_KEY_PARAMS_SIZE 6
19 #endif
20 /* --------------- Code_cpp block 0 end --------------- */
21 
22 #define TAG "Lwm2mSecurity"
23 
24 namespace wpp {
25 
26 Lwm2mSecurity::Lwm2mSecurity(lwm2m_context_t &context, const OBJ_LINK_T &id): Instance(context, id) {
27 
28  /* --------------- Code_cpp block 1 start --------------- */
29  /* --------------- Code_cpp block 1 end --------------- */
30 
31  resourcesCreate();
32  resourcesInit();
33 
34  /* --------------- Code_cpp block 2 start --------------- */
35  /* --------------- Code_cpp block 2 end --------------- */
36 }
37 
39  /* --------------- Code_cpp block 3 start --------------- */
40  /* --------------- Code_cpp block 3 end --------------- */
41 }
42 
44  return ctx.registry().lwm2mSecurity();
45 }
46 
48  Instance *inst = ctx.registry().lwm2mSecurity().instance(instId);
49  if (!inst) return NULL;
50  return static_cast<Lwm2mSecurity*>(inst);
51 }
52 
54  Instance *inst = ctx.registry().lwm2mSecurity().createInstance(instId);
55  if (!inst) return NULL;
56  return static_cast<Lwm2mSecurity*>(inst);
57 }
58 
60  return ctx.registry().lwm2mSecurity().remove(instId);
61 }
62 
63 void Lwm2mSecurity::serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) {
64  /* --------------- Code_cpp block 4 start --------------- */
65  /* --------------- Code_cpp block 4 end --------------- */
66 
67  operationNotify(*this, resLink, type);
68 
69  /* --------------- Code_cpp block 5 start --------------- */
70  /* --------------- Code_cpp block 5 end --------------- */
71 }
72 
74  if (type == ItemOp::WRITE || type == ItemOp::DELETE) notifyResChanged(resLink.resId, resLink.resInstId);
75 
76  /* --------------- Code_cpp block 6 start --------------- */
77  /* --------------- Code_cpp block 6 end --------------- */
78 }
79 
80 void Lwm2mSecurity::resourcesCreate() {
81  std::vector<Resource> resources = {
88  #if RES_0_6
90  #endif
91  #if RES_0_7
92  {SMS_BINDING_KEY_PARAMETERS_7, ItemOp(ItemOp::READ|ItemOp::WRITE), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::OPAQUE },
93  #endif
94  #if RES_0_8
95  {SMS_BINDING_SECRET_KEY_S__8, ItemOp(ItemOp::READ|ItemOp::WRITE), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::OPAQUE },
96  #endif
97  #if RES_0_9
98  {LWM2M_SERVER_SMS_NUMBER_9, ItemOp(ItemOp::READ|ItemOp::WRITE), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::STRING },
99  #endif
100  #if RES_0_10
102  #endif
103  #if RES_0_11
105  #endif
106  #if RES_0_12
108  #endif
109  #if RES_0_13
111  #endif
112  #if RES_0_14
114  #endif
115  #if RES_0_15
117  #endif
118  #if RES_0_16
120  #endif
121  #if RES_0_17
123  #endif
124  };
125  setupResources(std::move(resources));
126 }
127 
128 void Lwm2mSecurity::resourcesInit() {
129  /* --------------- Code_cpp block 7 start --------------- */
131  resource(LWM2M_SERVER_URI_0)->setDataVerifier((VERIFY_STRING_T)[](const STRING_T& value) { return value.size() < SERVER_URI_MAX_SIZE; });
132 
134 
135  resource(SECURITY_MODE_2)->set<INT_T>(LWM2M_SECURITY_MODE_NONE);
136  resource(SECURITY_MODE_2)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return LWM2M_SECURITY_MODE_PRE_SHARED_KEY <= value && value <= LWM2M_SECURITY_MODE_NONE; });
137 
139 
141 
143 
144  #if RES_0_6
145  resource(SMS_SECURITY_MODE_6)->set<INT_T>(SMS_SEC_MODE_MAX);
146  resource(SMS_SECURITY_MODE_6)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return SMS_SEC_MODE_MIN <= value && value <= SMS_SEC_MODE_MAX; });
147  #endif
148 
149  #if RES_0_7
150  resource(SMS_BINDING_KEY_PARAMETERS_7)->set<OPAQUE_T>({});
151  resource(SMS_BINDING_KEY_PARAMETERS_7)->setDataVerifier((VERIFY_OPAQUE_T)[](const OPAQUE_T& value) { return value.size() == SMS_BIND_KEY_PARAMS_SIZE; });
152  #endif
153 
154  #if RES_0_8_
155  resource(SMS_BINDING_SECRET_KEY_S__8)->set<OPAQUE_T>({});
156  resource(SMS_BINDING_SECRET_KEY_S__8)->setDataVerifier((VERIFY_OPAQUE_T)[](const OPAQUE_T& value) { return MIN_SMS_KEY_LEN <= value.size() && value.size() <= MAX_SMS_KEY_LEN; });
157  #endif
158 
159  #if RES_0_9
160  resource(LWM2M_SERVER_SMS_NUMBER_9)->set<STRING_T>("");
161  #endif
162 
163  #if RES_0_10
165  resource(SHORT_SERVER_ID_10)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return SINGLE_INSTANCE_ID < value && value < ID_T_MAX_VAL; });
166  #endif
167 
168  #if RES_0_11
170  #endif
171 
172  #if RES_0_12
174  #endif
175 
176  #if RES_0_13
177  resource(MATCHING_TYPE_13)->set<UINT_T>(MAX_MATCH_TYPE);
178  resource(MATCHING_TYPE_13)->setDataVerifier((VERIFY_UINT_T)[](const UINT_T& value) { return EXACT_MATCH <= value && value < MAX_MATCH_TYPE; });
179  #endif
180 
181  #if RES_0_14
182  resource(SNI_14)->set<STRING_T>("");
183  #endif
184 
185  #if RES_0_15
186  resource(CERTIFICATE_USAGE_15)->set<UINT_T>(MAX_CERT_USAGE);
187  resource(CERTIFICATE_USAGE_15)->setDataVerifier((VERIFY_UINT_T)[](const UINT_T& value) { return CA_CONSTRAINT <= value && value < MAX_CERT_USAGE; });
188  #endif
189 
190  #if RES_0_16
191  #endif
192 
193  #if RES_0_17
194  resource(OSCORE_SECURITY_MODE_17)->set<OBJ_LINK_T>({});
195  #endif
196  /* --------------- Code_cpp block 7 end --------------- */
197 }
198 
199 /* --------------- Code_cpp block 8 start --------------- */
200 /* --------------- Code_cpp block 8 end --------------- */
201 
202 } /* namespace wpp */
#define SERVER_URI_MAX_SIZE
#define SINGLE_INSTANCE_ID
Definition: WppTypes.h:13
#define ID_T_MAX_VAL
Definition: WppTypes.h:16
void operationNotify(Instance &inst, const ResLink &resLink, ItemOp::TYPE type)
Notifies the observers about an operation on an instance resource.
Definition: InstSubject.h:78
Instance is interface class that implements manipulation with derived class resources....
Definition: Instance.h:40
void notifyResChanged(ID_T resId, ID_T resInstId=ID_T_MAX_VAL)
Notify server about resource value change.
Definition: Instance.cpp:17
static Object & object(WppClient &ctx)
Gets the Object reference.
Lwm2mSecurity(lwm2m_context_t &context, const OBJ_LINK_T &id)
static Lwm2mSecurity * createInst(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Creates an instance of the object.
static Lwm2mSecurity * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
static bool removeInst(WppClient &ctx, ID_T instId)
Removes an instance of the object.
void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
@ BOOTSTRAP_SERVER_ACCOUNT_TIMEOUT_12
Definition: Lwm2mSecurity.h:54
void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
The Object class implements manipulation with Instance interface class and its inheritors.
Definition: Object.h:32
Instance * instance(ID_T instanceID=ID_T_MAX_VAL)
Gets an instance of the object.
Definition: Object.cpp:102
virtual Instance * createInstance(ID_T instanceID=ID_T_MAX_VAL)=0
Creates an instance of the object.
bool remove(ID_T instanceID)
Removes an instance of the object.
Definition: Object.cpp:82
void setupResources(const std::vector< Resource > &resources)
This methods setup resources list.
Resource * resource(ID_T resId)
This method return resource ptr if it exists. If resources does not exist then return NULL.
std::vector< Resource > & resources()
This method return list with all resources that has been defined.
bool set(const T &value, ID_T resInstId=SINGLE_INSTANCE_ID)
Set data value by copy for the resource (instance)
Definition: Resource.h:253
bool setDataVerifier(const DATA_VERIFIER_T &verifier)
Set data verifier for the resource.
Definition: Resource.cpp:164
Represents a client interface for Wpp library.
Definition: WppClient.h:37
WppRegistry & registry()
Gets the WppRegistry associated with the WppClient.
Definition: WppClient.cpp:93
Object & lwm2mSecurity()
Definition: WppRegistry.cpp:86
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
bool BOOL_T
Wpp data types bindings.
Definition: WppTypes.h:40
int64_t INT_T
Definition: WppTypes.h:41
uint16_t ID_T
Definition: WppTypes.h:15
std::function< bool(const STRING_T &)> VERIFY_STRING_T
Definition: WppTypes.h:100
std::function< bool(const INT_T &)> VERIFY_INT_T
Data validation function types.
Definition: WppTypes.h:94
uint64_t UINT_T
Definition: WppTypes.h:42
std::string STRING_T
Definition: WppTypes.h:45
std::function< bool(const UINT_T &)> VERIFY_UINT_T
Definition: WppTypes.h:95
std::vector< uint8_t > OPAQUE_T
Opaque - represent buffer or string as lwm2m_data_t.value.asBuffer.
Definition: WppTypes.h:49
std::function< bool(const OPAQUE_T &)> VERIFY_OPAQUE_T
Definition: WppTypes.h:97
The ItemOp struct represents the operations that can be performed on a instance/resource.
Definition: ItemOp.h:24
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29
@ DELETE
Definition: ItemOp.h:36