Awa LWM2M C API (0.2.5)  
static.h
Go to the documentation of this file.
1 /************************************************************************************************************************
2  Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies.
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6  following conditions are met:
7  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8  following disclaimer.
9  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10  following disclaimer in the documentation and/or other materials provided with the distribution.
11  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
12  products derived from this software without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
20  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 ************************************************************************************************************************/
22 
23 
39 #ifndef AWA_STATIC_H
40 #define AWA_STATIC_H
41 
42 // @cond
43 #include <stdint.h>
44 #include <stdbool.h>
45 // @endcond
46 
47 #include "types.h"
48 #include "error.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /**************************************************************************************************
55  * Example Usage
56  *************************************************************************************************/
57 
68 /**************************************************************************************************
69  * Public Types and Enumerations
70  *************************************************************************************************/
71 
75 typedef enum
76 {
84 } AwaOperation;
85 
91 typedef struct _AwaStaticClient AwaStaticClient;
92 
96 typedef enum
97 {
103 
104 #define BOOTSTRAP_CONFIG_SERVER_URI_SIZE (256)
105 #define BOOTSTRAP_CONFIG_PUBLIC_KEY_SIZE (128)
106 #define BOOTSTRAP_CONFIG_SERVER_KEY_SIZE (128)
107 #define BOOTSTRAP_CONFIG_SECRET_KEY_SIZE (128)
108 #define BOOTSTRAP_CONFIG_BINDING_SIZE (10)
114 typedef struct
115 {
120  struct
121  {
123  AwaSecurityMode SecurityMode;
124  char PublicKeyOrIdentity[BOOTSTRAP_CONFIG_PUBLIC_KEY_SIZE];
125  char ServerPublicKey[BOOTSTRAP_CONFIG_SERVER_KEY_SIZE];
127  } SecurityInfo;
128 
133  struct
134  {
135  int Lifetime;
141  } ServerInfo;
143 
147 typedef enum
148 {
170 } AwaResult;
171 
172 
173 /**************************************************************************************************
174  * Callbacks
175  *************************************************************************************************/
176 
203 typedef AwaResult (*AwaStaticClientHandler)(AwaStaticClient * client, AwaOperation operation,
204  AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID,
205  void ** dataPointer, size_t * dataSize, bool * changed);
206 
207 
208 /************************************************************************************************************
209  * Awa Static Client Initialisation and Teardown
210  ************************************************************************************************************/
211 
222 
231 
238 
252 
265 AwaError AwaStaticClient_SetEndPointName(AwaStaticClient * client, const char * endPointName);
266 
282 AwaError AwaStaticClient_SetCoAPListenAddressPort(AwaStaticClient * client, const char * address, int port);
283 
303 AwaError AwaStaticClient_SetBootstrapServerURI(AwaStaticClient * client, const char * bootstrapServerURI);
304 
322 
333 void AwaStaticClient_SetCertificate(AwaStaticClient * client, const uint8_t * certificate, int certificateLength, AwaCertificateFormat format);
334 
345 void AwaStaticClient_SetPSK(AwaStaticClient * client, const char * identity, const uint8_t * key, int keyLength);
346 
361 
374 
384 
413 
423 void AwaStaticClient_Free(AwaStaticClient ** client);
424 
425 
426 /************************************************************************************************************
427  * Awa Static Client Object and Resource Definition
428  ************************************************************************************************************/
429 
449 AwaError AwaStaticClient_DefineObject(AwaStaticClient * client, AwaObjectID objectID, const char * objectName,
450  uint16_t minimumInstances, uint16_t maximumInstances);
451 
465 
491  const char * resourceName, AwaResourceType resourceType,
492  uint16_t minimumInstances, uint16_t maximumInstances, AwaResourceOperations operations);
493 
511 
534 AwaError AwaStaticClient_SetResourceStorageWithPointer(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID, void * dataPointer, size_t dataElementSize, size_t dataStepSize);
535 
558 AwaError AwaStaticClient_SetResourceStorageWithPointerArray(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID, void * dataPointers[], size_t dataElementSize);
559 
560 
561 /************************************************************************************************************
562  * Awa Static Client Processing
563  ************************************************************************************************************/
564 
579 
580 
581 /************************************************************************************************************
582  * Awa Static Client Object and Resource Manipulation
583  ************************************************************************************************************/
584 
599 const void * AwaStaticClient_GetResourceInstancePointer(AwaStaticClient * client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID, size_t * resourceSize);
600 
617 
634 
647 
660 
674 
689 
690 #ifdef __cplusplus
691 }
692 #endif
693 
694 #endif /* AWA_STATIC_CLIENT_H */
indicates the specified object, object instance or resource does not exist
Definition: static.h:158
AwaError
API Error Codes.
Definition: error.h:38
AwaClientRegistrationStatus AwaStaticClient_GetRegistrationStatus(AwaStaticClient *client)
Retrieve register status for the Awa Static Client.
indicates the requested target was created successfully
Definition: static.h:150
AwaError AwaStaticClient_CreateObjectInstance(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID)
Create an object instance within the specified object.
#define BOOTSTRAP_CONFIG_BINDING_SIZE
Maximum length in characters of Binding string.
Definition: static.h:108
indicates a request to create a resource
Definition: static.h:82
Provides definitions for types and enums used by Awa LWM2M API and Static API.
indicates Pre-Shared Key security mode (PSK)
Definition: static.h:98
AwaError AwaStaticClient_DefineObject(AwaStaticClient *client, AwaObjectID objectID, const char *objectName, uint16_t minimumInstances, uint16_t maximumInstances)
Define a new custom LWM2M object.
AwaError AwaStaticClient_DeleteObjectInstance(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID)
Delete an object instance within the specified object.
indicates an invalid argument or request to create an entity that already exists
Definition: static.h:155
indicates a successful read from a resource
Definition: static.h:153
#define BOOTSTRAP_CONFIG_PUBLIC_KEY_SIZE
Maximum size in bytes of Public Key / Identity opaque value.
Definition: static.h:105
AwaResult(* AwaStaticClientHandler)(AwaStaticClient *client, AwaOperation operation, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID, void **dataPointer, size_t *dataSize, bool *changed)
A user-specified callback handler for a LWM2M Operation on the specified /O/I/R/i path to an LWM2M en...
Definition: static.h:203
AwaError AwaStaticClient_SetApplicationContext(AwaStaticClient *client, void *context)
Set a user-specified application context which is accessible to any defined callback handler owned by...
indicates a request to delete an object instance
Definition: static.h:78
indicates a successful write to a resource
Definition: static.h:152
int AwaResourceInstanceID
Definition: types.h:46
AwaStaticClient * AwaStaticClient_New(void)
Allocate and return a pointer to a new Awa Static Client.
AwaError AwaStaticClient_DeleteResource(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID)
Delete an optional resource within the specified object instance.
AwaError AwaStaticClient_SetEndPointName(AwaStaticClient *client, const char *endPointName)
Set the client endpoint name.
AwaError AwaStaticClient_ResourceChanged(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID)
Mark the specified resource as changed, in order for the Awa Static Client to send notifications to a...
indicates the requested operation completed successfully
Definition: static.h:149
AwaClientRegistrationStatus
Definition: types.h:185
#define BOOTSTRAP_CONFIG_SECRET_KEY_SIZE
Maximum size in bytes of Secret Key opaque value.
Definition: static.h:107
indicates an attempt to call the requested operation with insufficient authorisation ...
Definition: static.h:156
int Lifetime
Specify the lifetime of the registration in seconds.
Definition: static.h:135
AwaError AwaStaticClient_SetResourceStorageWithPointer(AwaStaticClient *client, AwaObjectID objectID, AwaResourceID resourceID, void *dataPointer, size_t dataElementSize, size_t dataStepSize)
Set a resource&#39;s storage with a pointer to the resource&#39;s data, leaving handling of the resource to t...
indicates a requested accept-header was not acceptable by the client daemon
Definition: static.h:160
indicates a request to read from a resource
Definition: static.h:79
AwaError AwaStaticClient_SetCoAPListenAddressPort(AwaStaticClient *client, const char *address, int port)
Set the address and port to listen on for incoming CoAP packets.
AwaError AwaStaticClient_Init(AwaStaticClient *client)
Initialise an Awa Static client.
AwaContentType
Definition: types.h:170
Provides definitions for Awa LWM2M Client and Server API error codes and error function declarations...
indicates a request to delete a resource
Definition: static.h:83
struct _AwaStaticClient AwaStaticClient
Represents an Awa Static Client context, holding the necessary information to initialise the client d...
Definition: static.h:91
AwaSecurityMode
Supported LWM2M security modes.
Definition: static.h:96
int AwaObjectInstanceID
Definition: types.h:44
AwaOperation
Supported operations for resource and object handlers defined with AwaStaticClient_DefineResource.
Definition: static.h:75
indicates a request to create an object instance
Definition: static.h:77
void AwaStaticClient_Free(AwaStaticClient **client)
Free an Awa Static Client.
AwaResourceOperations
Supported resource operations for management servers.
Definition: types.h:133
int AwaStaticClient_Process(AwaStaticClient *client)
Process the Awa Static Client.
AwaError AwaStaticClient_DefineResource(AwaStaticClient *client, AwaObjectID objectID, AwaResourceID resourceID, const char *resourceName, AwaResourceType resourceType, uint16_t minimumInstances, uint16_t maximumInstances, AwaResourceOperations operations)
Define a new resource as part of a defined object.
#define BOOTSTRAP_CONFIG_SERVER_URI_SIZE
Maximum size in characters of Server URI string.
Definition: static.h:104
AwaError AwaStaticClient_ObjectInstanceChanged(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID)
Mark the specified object instance as changed, in order for the Awa Static Client to send notificatio...
indicates an attempt to define an already defined object or resource
Definition: static.h:165
#define BOOTSTRAP_CONFIG_SERVER_KEY_SIZE
Maximum size in bytes of Server Key opaque value.
Definition: static.h:106
indicates the requested target was deleted successfully
Definition: static.h:151
int DisableTimeout
Specify the period to disable the Server.
Definition: static.h:138
indicates the handler did not have sufficient memory to service the requested operation ...
Definition: static.h:164
indicates Raw Public Key security mode (RPK)
Definition: static.h:99
int DefaultMinPeriod
Specify the default value the LWM2M Client should use for the Minimum Period of an Observation in the...
Definition: static.h:136
indicates the requested operation is not supported by the called handler
Definition: static.h:168
void * AwaStaticClient_GetApplicationContext(AwaStaticClient *client)
Retrieve a user-specified application context as a void pointer.
indicates No Security mode
Definition: static.h:101
AwaError AwaStaticClient_SetResourceStorageWithPointerArray(AwaStaticClient *client, AwaObjectID objectID, AwaResourceID resourceID, void *dataPointers[], size_t dataElementSize)
Set a resource&#39;s storage with an array of pointers to non-contiguous data, where each piece of data s...
const void * AwaStaticClient_GetResourceInstancePointer(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID, size_t *resourceSize)
Retrieve a pointer to a resource instance&#39;s data, when defined with AwaStaticClient_SetResourceStorag...
AwaError AwaStaticClient_SetResourceOperationHandler(AwaStaticClient *client, AwaObjectID objectID, AwaResourceID resourceID, AwaStaticClientHandler handler)
Set a user-specified callback handler that will be called whenever a LWM2M operation on the resource ...
indicates Certificate-based security mode
Definition: static.h:100
void AwaStaticClient_SetDefaultContentType(AwaContentType contentType)
Set the default content type to use when a request doesn&#39;t specify via accept header a preferred cont...
AwaContentType AwaStaticClient_GetDefaultContentType(void)
Retrieve default content type to use when a request doesn&#39;t specify via accept header a preferred con...
void AwaStaticClient_SetCertificate(AwaStaticClient *client, const uint8_t *certificate, int certificateLength, AwaCertificateFormat format)
Configure default certificate to use when Awa Static Client connects to a secure Server/Bootstrap.
indicates the requested operation is not allowed for the specified target
Definition: static.h:159
AwaError AwaStaticClient_SetBootstrapServerURI(AwaStaticClient *client, const char *bootstrapServerURI)
Set the network location of a trusted LWM2M Bootstrap server, in the URI format: "coap://[address]:[p...
int DefaultMaxPeriod
Specify the default value the LWM2M Client should use for the Maximum Period of an Observation in the...
Definition: static.h:137
AwaError AwaStaticClient_CreateResource(AwaStaticClient *client, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID)
Create an optional resource within the specified object instance.
int AwaObjectID
Definition: types.h:43
indicates a request to write to a resource
Definition: static.h:81
indicates an attempt to define an object that does not match the existing definition ...
Definition: static.h:166
indicates an attempt to create an existing resource or object instance
Definition: static.h:167
AwaSecurityMode SecurityMode
Specifies the LWM2M Security Mode.
Definition: static.h:123
AwaLogLevel
Supported log levels for a log command.
Definition: types.h:150
int AwaResourceID
Definition: types.h:45
AwaResult
Supported result codes for handler callbacks.
Definition: static.h:147
indicates the requested operation was ignored by the called handler
Definition: static.h:169
void AwaStaticClient_SetPSK(AwaStaticClient *client, const char *identity, const uint8_t *key, int keyLength)
Configure default PSK to use when Awa Static Client connects to a secure Server/Bootstrap.
AwaResourceType
Supported resource types.
Definition: types.h:101
indicates a request to create an object instance
Definition: static.h:157
indicates the handler failed internally while processing a request
Definition: static.h:162
indicates a request to write to a resource
Definition: static.h:80
bool Notification
Specify Notification Storing When Disabled or Offline: if true, the LWM2M Client stores “Notify” op...
Definition: static.h:139
AwaError AwaStaticClient_SetObjectOperationHandler(AwaStaticClient *client, AwaObjectID objectID, AwaStaticClientHandler handler)
Set the Object Operation handler function, to be called by the LWM2M Client when object instances are...
AwaCertificateFormat
Supported Certificate formats.
Definition: types.h:162
Information required to bootstrap the client daemon from a factory configuration. ...
Definition: static.h:114
AwaError AwaStaticClient_SetLogLevel(AwaLogLevel level)
Set the client log level.
AwaError AwaStaticClient_SetFactoryBootstrapInformation(AwaStaticClient *client, const AwaFactoryBootstrapInfo *factoryBootstrapInformation)
Configure factory bootstrap by supplying LWM2M Server Bootstrap Information to register with a LWM2M ...