#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <unistd.h>
#define LOCATION_OBJ_ID (6)
#define LONGITUDE_ID (1)
#define LATITUDE_ID (0)
#define TIMESTAMP_ID (5)
#define PSK_KEY_LEN 16
#define RPK_PRIVATE_KEY_LEN 32
#define RPK_PUBLIC_KEY_LEN (2 * RPK_PRIVATE_KEY_LEN)
#define CLIENT_SERVER_PSK_ID ("cli1")
#define CLIENT_SERVER_PSK_KEY ("0123456789ABCDEF")
#define CLIENT_PUBLIC_KEY ("D055EE14084D6E0615599DB583913E4A3E4526A2704D61F27A4CCFBA9758EF9A" \
"B418B64AFE8030DA1DDCF4F42E2F2631D043B1FB03E22F4D17DE43F9F9ADEE70")
#define SERVER_PRIVATE_KEY ("65c5e815d0c40e8f99143e5c905cbd9026444395af207a914063d8f0a7e63f22")
#define SERVER_PUBLIC_KEY ("3b88c213ca5ccfd9c5a7f73715760d7d9a5220768f2992d2628ae1389cbca4c6" \
"d1b73cc6d61ae58783135749fb03eaaa64a7a1adab8062ed5fc0d7b86ba2d5ca")
};
.parent = NULL,
.mem = (void *)"48.858093",
.
size =
sizeof(
"48.858093") - 1,
.refcnt = 1
};
.parent = NULL,
.mem = (void *)"2.294694",
.
size =
sizeof(
"2.294694") - 1,
.refcnt = 1
};
{
uint16_t i;
uint16_t id;
int r;
if (r < 0) {
fprintf(stderr, "Could not fetch the object id from %p\n", object);
}
continue;
}
}
static void
const char *path,
{
int r;
uint16_t i;
fprintf(stderr, "Could not get the location object value from"
" client %s\n", name);
return;
}
fprintf(stderr, "The location object content from client %s is not"
" in TLV format. Received format: %d\n", name, content_type);
return;
}
if (r < 0) {
fprintf(stderr, "Could not parse the tlv from client: %s\n", name);
return;
}
const char *prop;
prop = "latitude";
prop = "longitude";
else
continue;
if (r < 0) {
fprintf(stderr, "Could not get the %s value from client %s\n",
prop, name);
break;
}
printf("Client %s %s is %.*s\n", name, prop, (int)buf.used, (char *)buf.data);
}
}
static void
{
int r;
if (r < 0)
fprintf(stderr, "Could not send an observe request to the location"
" object\n");
else
printf("Observe request to the location object sent\n");
}
static void
{
fprintf(stderr, "The client %s could not create the location object.\n",
name);
return;
}
printf("The client %s created the location object."
" Observing it now.\n", name);
}
static void
{
int r;
size_t i;
if (r < 0) {
fprintf(stderr, "Could init the latitude resource\n");
return;
}
if (r < 0) {
fprintf(stderr, "Could not init the longitude resource\n");
return;
}
(int64_t)time(NULL));
if (r < 0) {
fprintf(stderr, "Could not init the timestamp resource\n");
return;
}
if (r < 0)
fprintf(stderr, "Could not send a request to create a"
" location object\n");
else
printf("Creation request sent\n");
}
static void
{
const char *name;
printf("Client %s updated\n", name);
return;
printf("Client %s unregistered\n", name);
return;
printf("Client %s timeout\n", name);
return;
}
printf("Client %s registered\n", name);
fprintf(stderr,
"The client %s does not implement the location object!\n",
name);
printf("The client %s does not have an instance of the location"
" object. Creating one.\n", name);
} else {
printf("The client %s have an location object instance,"
" observing\n", name);
}
}
int
main(
int argc,
char *argv[])
{
int r;
.id = NULL,
.key = NULL
}),
NULL
};
struct sol_blob *known_pub_keys[] = { NULL, NULL };
snprintf(usage, sizeof(usage),
"Usage: ./lwm2m-sample-server [-c PORT] [-d PORT] [-s SEC_MODE]\n"
"Where default CoAP PORT=%d, default DTLS PORT=%d"
" and SEC_MODE is an integer as per:\n"
"\tPRE_SHARED_KEY=%d\n"
"\tRAW_PUBLIC_KEY=%d\n"
"\tCERTIFICATE=%d\n"
"\tNO_SEC=%d (default)\n",
while ((r = getopt(argc, argv, "c:d:s:")) != -1) {
switch (r) {
case 'c':
coap_port = atoi(optarg);
break;
case 'd':
dtls_port = atoi(optarg);
break;
case 's':
sec_mode = atoi(optarg);
if (sec_mode < 0 || sec_mode > 3) {
fprintf(stderr, "%s", usage);
return -1;
}
break;
default:
fprintf(stderr, "%s", usage);
return -1;
}
}
printf("Using LWM2M port %" PRIu16 " for CoAP", coap_port);
printf(" and port %" PRIu16 " for DTLS", dtls_port);
printf("\n");
} else {
}
if (!server) {
r = -1;
fprintf(stderr, "Could not create the LWM2M server\n");
goto exit;
}
NULL);
if (r < 0) {
fprintf(stderr, "Could not add a registration monitor\n");
goto exit_del;
}
r = 0;
exit_del:
exit:
}
return r;
}