RDK Documentation (Open Sourced RDK Components)
webpa_adapter.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
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  * @file webpa_adapter.h
22  *
23  * @description This header defines the WebPA Abstraction APIs
24  *
25  */
26 
27 #ifndef _WEBPA_ADAPTER_H_
28 #define _WEBPA_ADAPTER_H_
29 
30 #include <stddef.h>
31 #include <stdlib.h>
32 #include <stdint.h>
33 #include "waldb.h"
34 /**
35  * @brief Platform specific defines.
36  */
37 
38 #define WEBPA_CFG_FILE_NAME "webpa_cfg.json"
39 #define WEBPA_CFG_SERVER_IP "ServerIP"
40 #define WEBPA_CFG_SERVER_PORT "ServerPort"
41 #define WEBPA_CFG_SERVER_SECURE "Secure"
42 #define WEBPA_CFG_DEVICE_NW_INTERFACE "DeviceNetworkInterface"
43 #define WEBPA_CFG_RETRY_INTERVAL "RetryIntervalInSec"
44 #define WEBPA_CFG_PING_WAIT_TIME "MaxPingWaitTimeInSec"
45 #define WEBPA_CFG_NOTIFY "Notify"
46 #define WEBPA_CFG_FIRMWARE_VER "oldFirmwareVersion"
47 #define PARAM_CID "Device.DeviceInfo.Webpa.X_COMCAST-COM_CID"
48 #define PARAM_CMC "Device.DeviceInfo.Webpa.X_COMCAST-COM_CMC"
49 
50 #define LOG_PARODUS_IF "LOG.RDK.PARODUSIF"
51 #define WAL_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;}
52 
53 #define MAX_PARAMETER_LEN 512
54 #define RDKC_XPC_SYNC_PARAM_CID
55 #define MAX_PARAMETERNAME_LEN 256
56 
57 /**
58  * @brief WebPA Error codes.
59  */
60 typedef enum
61 {
62  WAL_SUCCESS = 0, /**< Success. */
63  WAL_FAILURE, /**< General Failure */
64  WAL_ERR_TIMEOUT,
65  WAL_ERR_NOT_EXIST,
66  WAL_ERR_INVALID_PARAMETER_NAME,
67  WAL_ERR_INVALID_PARAMETER_TYPE,
68  WAL_ERR_INVALID_PARAMETER_VALUE,
69  WAL_ERR_NOT_WRITABLE,
70  WAL_ERR_SETATTRIBUTE_REJECTED,
71  WAL_ERR_NAMESPACE_OVERLAP,
72  WAL_ERR_UNKNOWN_COMPONENT,
73  WAL_ERR_NAMESPACE_MISMATCH,
74  WAL_ERR_UNSUPPORTED_NAMESPACE,
75  WAL_ERR_DP_COMPONENT_VERSION_MISMATCH,
76  WAL_ERR_INVALID_PARAM,
77  WAL_ERR_UNSUPPORTED_DATATYPE,
78  WAL_STATUS_RESOURCES,
79  WAL_ERR_WIFI_BUSY
80 } WAL_STATUS;
81 
82 /**
83  * @brief Component or source that changed a param value.
84  */
85 typedef enum
86 {
87  CHANGED_BY_FACTORY_DEFAULT = (1<<0), /**< Factory Defaults */
88  CHANGED_BY_ACS = (1<<1), /**< ACS/TR-069 */
89  CHANGED_BY_WEBPA = (1<<2), /**< WebPA */
90  CHANGED_BY_CLI = (1<<3), /**< Command Line Interface (CLI) */
91  CHANGED_BY_SNMP = (1<<4), /**< SNMP */
92  CHANGED_BY_FIRMWARE_UPGRADE = (1<<5), /**< Firmware Upgrade */
93  CHANGED_BY_WEBUI = (1<<7), /**< Local Web UI (HTTP) */
94  CHANGED_BY_UNKNOWN = (1<<8), /**< Unknown */
95  CHANGED_BY_XPC = (1<<9) /**< xPC */
97 
98 /**
99  * @brief Set operations supported by WebPA.
100  */
101 typedef enum
102 {
103  WEBPA_SET = 0,
104  WEBPA_ATOMIC_SET,
105  WEBPA_ATOMIC_SET_XPC
107 
108 
109 /**
110  * @brief WebPA Data types.
111  */
112 typedef enum
113 {
114  WAL_STRING = 0,
115  WAL_INT,
116  WAL_UINT,
117  WAL_BOOLEAN,
118  WAL_DATETIME,
119  WAL_BASE64,
120  WAL_LONG,
121  WAL_ULONG,
122  WAL_FLOAT,
123  WAL_DOUBLE,
124  WAL_BYTE,
125  WAL_NONE
126 } WAL_DATA_TYPE;
127 
128 
129 /**
130  * @brief WebPA Config params.
131  */
132 typedef enum
133 {
134  WCFG_COMPONENT_NAME = 0,
135  WCFG_CFG_FILE,
136  WCFG_CFG_FILE_SRC,
137  WCFG_DEVICE_INTERFACE,
138  WCFG_DEVICE_MAC,
139  WCFG_DEVICE_REBOOT_PARAM,
140  WCFG_DEVICE_REBOOT_VALUE,
141  WCFG_XPC_SYNC_PARAM_CID,
142  WCFG_XPC_SYNC_PARAM_CMC,
143  WCFG_FIRMWARE_VERSION,
144  WCFG_DEVICE_UP_TIME,
145  WCFG_MANUFACTURER,
146  WCFG_MODEL_NAME,
147  WCFG_XPC_SYNC_PARAM_SPV,
148  WCFG_PARAM_HOSTS_NAME,
149  WCFG_PARAM_HOSTS_VERSION,
150  WCFG_PARAM_SYSTEM_TIME,
151  WCFG_RECONNECT_REASON,
152  WCFG_REBOOT_REASON,
153  WCFG_REBOOT_COUNTER
155 
156 /**
157  * @brief Structure to store Parameter info or Attribute info.
158  */
159 typedef struct
160 {
161  char *name;
162  char *value;
163  WAL_DATA_TYPE type;
164 } ParamVal, AttrVal;
165 
166 /**
167  * @brief WEBPA Notification types.
168  */
169 typedef enum
170 {
171  PARAM_NOTIFY = 0,
172  UPSTREAM_MSG,
173  TRANS_STATUS,
174  CONNECTED_CLIENT_NOTIFY,
175  PARAM_VALUE_CHANGE_NOTIFY,
176  NOTIFY_TYPE_MAX
177 } NOTIFY_TYPE;
178 
179 
180 /**
181  * @brief Structure to return Parameter info in Notification callback.
182  */
183 typedef struct
184 {
185  char* notifyDest;
186  char* notifyPayload;
187 } ParamNotify;
188 
189 
190 typedef struct
191 {
192  char *transId;
193 } TransData;
194 
195 typedef struct
196 {
197  char *nodeMacId;
198  char *status;
199 } NodeData;
200 
201 typedef union
202 {
203  ParamNotify *notify;
204  TransData * status;
205  NodeData * node;
206 } Notify_Data;
207 
208 typedef struct
209 {
210  NOTIFY_TYPE type;
211  Notify_Data *data;
212 } NotifyData;
213 
214 
215 /**
216  * @brief WebPA Configuration parameters.
217  */
218 typedef struct
219 {
220  char interfaceName[16];
221  char serverIP[256];
222  unsigned int serverPort;
223  int secureFlag;
224  unsigned int retryIntervalInSec;
225  unsigned int maxPingWaitTimeInSec;
226  char oldFirmwareVersion[256];
227 } WebPaCfg;
228 
229 /**
230  * @brief Initializes the Message Bus and registers WebPA component with the stack.
231  *
232  * @param[in] name WebPA Component Name.
233  * @return WAL_STATUS.
234  */
235 WAL_STATUS msgBusInit(const char *name);
236 
237 /**
238  * @brief Registers the notification callback function.
239  *
240  * @param[in] cb Notification callback function.
241  * @return WAL_STATUS.
242  */
244 
245 
246 /**
247  * @brief Set Notify configuration file
248  *
249  * @param[in] config file name
250  */
251 
252 void setInitialNotifyConfigFile(const char* nofityConfigFile);
253 
254 /**
255  * @brief processRequest processes the request and returns response payload
256  *
257  * @param[in] reqPayload input request to process
258  * @param[in] resPayload retuns response payload
259  */
260 void processRequest(char *reqPayload, char *transactionId, char **resPayload);
261 
262 /* @brief Loads the data-model xml data
263  *
264  * @return DB_STATUS
265  */
266 DB_STATUS LoadDataModel(void);
267 
268 /* @brief Loads the data-model xml data
269  *
270  * @return DB_STATUS
271  */
272 int getDBHandle();
273 
274 /* @brief Set the Initial Notify Parameters from config file
275  *
276  * @return void
277  */
278 void setInitialNotify(void);
279 
280 /* @brief Set the Initial Notify Parameters from config file
281  *
282  * @return void
283  */
285 
286 /**
287  * @brief Loads the WebPA config file, parses it and extracts the WebPA config parameters.
288  *
289  * @param[in] cfgFileName Config filename (with absolute path)
290  * @param[out] cfg WebPA config parameters
291  * @return WAL_STATUS
292  */
293 WAL_STATUS loadCfgFile(const char *cfgFileName, WebPaCfg *cfg);
294 
295 /**
296  * @brief WALInit Initalize wal
297  */
298 void WALInit();
299 
300 /**
301  * @brief LOGInit Initialize RDK Logger
302  */
303 void LOGInit();
304 
305 /**
306  * @brief waitForConnectReadyCondition wait till all dependent components
307  * required for connecting to server are initialized
308  */
310 
311 /**
312  * @brief waitForOperationalReadyCondition wait till all dependent components
313  * required for being operational are initialized
314  */
316 
317 /**
318  * @brief _WEBPA_LOG WEBPA RDK logger API
319  */
320 
321 void _WEBPA_LOG(unsigned int level, const char *msg, ...)
322 __attribute__((format (printf, 2, 3)));
323 
324 /**
325  * @brief getWebPAConfig interface returns the WebPA config data.
326  *
327  * @param[in] param WebPA config param name.
328  * @return const char* WebPA config param value.
329  */
330 //const char* getWebPAConfig(WCFG_PARAM_NAME param);
331 
332 /**
333  * @brief sendIoTMessage interface sends message to IoT.
334  *
335  * @param[in] msg Message to be sent to IoT.
336  * @return WAL_STATUS
337  */
338 WAL_STATUS sendIoTMessage(const void *msg);
339 
340 
341 
342 void getCurrentTime(struct timespec *timer);
343 
344 #endif /* _WEBPA_ADAPTER_H_ */
345 
WebPaCfg
WebPA Configuration parameters.
Definition: webpa_adapter.h:218
CHANGED_BY_FIRMWARE_UPGRADE
@ CHANGED_BY_FIRMWARE_UPGRADE
Definition: webpa_adapter.h:92
NodeData
Definition: webpa_adapter.h:195
getCurrentTime
void getCurrentTime(struct timespec *timer)
Get Current time.
Definition: hostIf_utils.cpp:466
WCFG_PARAM_NAME
WCFG_PARAM_NAME
WebPA Config params.
Definition: webpa_adapter.h:132
CHANGED_BY_WEBUI
@ CHANGED_BY_WEBUI
Definition: webpa_adapter.h:93
CHANGED_BY_WEBPA
@ CHANGED_BY_WEBPA
Definition: webpa_adapter.h:89
WALInit
void WALInit()
WALInit Initalize wal.
CHANGED_BY_FACTORY_DEFAULT
@ CHANGED_BY_FACTORY_DEFAULT
Definition: webpa_adapter.h:87
CHANGED_BY_SNMP
@ CHANGED_BY_SNMP
Definition: webpa_adapter.h:91
WEBPA_SET_TYPE
WEBPA_SET_TYPE
Set operations supported by WebPA.
Definition: webpa_adapter.h:101
WAL_STATUS
WAL_STATUS
WebPA Error codes.
Definition: webpa_adapter.h:60
ParamNotify
Structure to return Parameter info in Notification callback.
Definition: webpa_adapter.h:183
processRequest
void processRequest(char *reqPayload, char *transactionId, char **resPayload)
processRequest processes the request and returns response payload
Definition: webpa_adapter.cpp:170
TransData
Definition: webpa_adapter.h:190
NotifyData
Definition: webpa_adapter.h:208
_WEBPA_LOG
void _WEBPA_LOG(unsigned int level, const char *msg,...) __attribute__((format(printf
_WEBPA_LOG WEBPA RDK logger API
WAL_DATA_TYPE
WAL_DATA_TYPE
WebPA Data types.
Definition: webpa_adapter.h:112
sendIoTMessage
void WAL_STATUS sendIoTMessage(const void *msg)
getWebPAConfig interface returns the WebPA config data.
setInitialNotifyConfigFile
void setInitialNotifyConfigFile(const char *nofityConfigFile)
Set Notify configuration file.
Definition: webpa_adapter.cpp:74
CHANGED_BY_ACS
@ CHANGED_BY_ACS
Definition: webpa_adapter.h:88
PARAMVAL_CHANGE_SOURCE
PARAMVAL_CHANGE_SOURCE
Component or source that changed a param value.
Definition: webpa_adapter.h:85
registerNotifyCallback
void registerNotifyCallback()
Registers the notification callback function.
Definition: webpa_adapter.cpp:83
CHANGED_BY_CLI
@ CHANGED_BY_CLI
Definition: webpa_adapter.h:90
loadCfgFile
WAL_STATUS loadCfgFile(const char *cfgFileName, WebPaCfg *cfg)
Loads the WebPA config file, parses it and extracts the WebPA config parameters.
WAL_FAILURE
@ WAL_FAILURE
Definition: webpa_adapter.h:63
msgBusInit
WAL_STATUS msgBusInit(const char *name)
Initializes the Message Bus and registers WebPA component with the stack.
NOTIFY_TYPE
NOTIFY_TYPE
WEBPA Notification types.
Definition: webpa_adapter.h:169
waitForOperationalReadyCondition
void waitForOperationalReadyCondition()
waitForOperationalReadyCondition wait till all dependent components required for being operational ar...
CHANGED_BY_UNKNOWN
@ CHANGED_BY_UNKNOWN
Definition: webpa_adapter.h:94
CHANGED_BY_XPC
@ CHANGED_BY_XPC
Definition: webpa_adapter.h:95
ParamVal
Structure to store Parameter info or Attribute info.
Definition: webpa_adapter.h:159
Notify_Data
Definition: webpa_adapter.h:201
setInitialNotify
void setInitialNotify(void)
Initializes WebPA configuration file.
Definition: webpa_adapter.cpp:108
WAL_SUCCESS
@ WAL_SUCCESS
Definition: webpa_adapter.h:62
waitForConnectReadyCondition
void waitForConnectReadyCondition()
waitForConnectReadyCondition wait till all dependent components required for connecting to server are...
LOGInit
void LOGInit()
LOGInit Initialize RDK Logger.