Skip to content

Commit

Permalink
Merge pull request #253 from delme-imgtec/dtls
Browse files Browse the repository at this point in the history
Change contiki to use network abstraction and awa erbium
  • Loading branch information
Rory Latchem authored Jul 21, 2016
2 parents aa71761 + 58f7285 commit c475ef2
Show file tree
Hide file tree
Showing 25 changed files with 933 additions and 828 deletions.
7 changes: 6 additions & 1 deletion core/src/client/awa_clientd.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ option "factoryBootstrap" f "Load factory bootstrap information from FILE"
option "secure" s "CoAP communications are secured with DTLS" flag off
option "pskIdentity" - "Default Identity of associated pre-shared key for DTLS"
string optional typestr="IDENTITY"
option "pskKey" - "Default pre-shared key for DTLS" string optional typestr="KEY"
option "pskKey" - "Default pre-shared key for DTLS as a hex string" string optional typestr="KEY"
option "certificate" c "Load client certificate from FILE" string optional typestr="FILE"

option "objDefs" o "Load object and resource definitions from FILE" string optional typestr="FILE" multiple(1-16)
Expand All @@ -29,3 +29,8 @@ text "\n"
text "Example:\n"
text " awa_clientd --port 6000 --endPointName client1 --bootstrap coap://[::1]:2134\n"
text "\n"

text "PSK Example:\n"
text "\n"
text " awa_clientd --port 6000 --endPointName client1 --bootstrap coaps://0.0.0.0:2134 --pskIdentity=myPskIdentity --pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n"
text "\n"
6 changes: 3 additions & 3 deletions core/src/client/awa_clientd_cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ const char *gengetopt_args_info_help[] = {
" -f, --factoryBootstrap=FILE Load factory bootstrap information from FILE",
" -s, --secure CoAP communications are secured with DTLS\n (default=off)",
" --pskIdentity=IDENTITY Default Identity of associated pre-shared key\n for DTLS",
" --pskKey=KEY Default pre-shared key for DTLS",
" --pskKey=KEY Default pre-shared key for DTLS as a hex string",
" -c, --certificate=FILE Load client certificate from FILE",
" -o, --objDefs=FILE Load object and resource definitions from FILE",
" -d, --daemonize Detach process from terminal and run in the\n background (default=off)",
" -v, --verbose Generate verbose output (default=off)",
" -l, --logFile=FILE Log output to FILE",
" -V, --version Print version and exit (default=off)",
"\nExample:\n awa_clientd --port 6000 --endPointName client1 --bootstrap\ncoap://[::1]:2134\n\n",
"\nExample:\n awa_clientd --port 6000 --endPointName client1 --bootstrap\ncoap://[::1]:2134\n\nPSK Example:\n\n awa_clientd --port 6000 --endPointName client1 --bootstrap\ncoaps://0.0.0.0:2134 --pskIdentity=myPskIdentity\n--pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n\n",
0
};

Expand Down Expand Up @@ -1772,7 +1772,7 @@ cmdline_parser_internal (
goto failure;

}
/* Default pre-shared key for DTLS. */
/* Default pre-shared key for DTLS as a hex string. */
else if (strcmp (long_options[option_index].name, "pskKey") == 0)
{

Expand Down
6 changes: 3 additions & 3 deletions core/src/client/awa_clientd_cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ struct gengetopt_args_info
char * pskIdentity_arg; /**< @brief Default Identity of associated pre-shared key for DTLS. */
char * pskIdentity_orig; /**< @brief Default Identity of associated pre-shared key for DTLS original value given at command line. */
const char *pskIdentity_help; /**< @brief Default Identity of associated pre-shared key for DTLS help description. */
char * pskKey_arg; /**< @brief Default pre-shared key for DTLS. */
char * pskKey_orig; /**< @brief Default pre-shared key for DTLS original value given at command line. */
const char *pskKey_help; /**< @brief Default pre-shared key for DTLS help description. */
char * pskKey_arg; /**< @brief Default pre-shared key for DTLS as a hex string. */
char * pskKey_orig; /**< @brief Default pre-shared key for DTLS as a hex string original value given at command line. */
const char *pskKey_help; /**< @brief Default pre-shared key for DTLS as a hex string help description. */
char * certificate_arg; /**< @brief Load client certificate from FILE. */
char * certificate_orig; /**< @brief Load client certificate from FILE original value given at command line. */
const char *certificate_help; /**< @brief Load client certificate from FILE help description. */
Expand Down
8 changes: 7 additions & 1 deletion core/src/client/lwm2m_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ uint8_t HexToByte(const char *value)
static int Lwm2mClient_Start(Options * options)
{
int result = 0;
uint8_t * key = NULL;

if (options->Daemonise)
{
Daemonise(options->Verbose);
Expand Down Expand Up @@ -228,7 +230,7 @@ static int Lwm2mClient_Start(Options * options)
{
int hexKeyLength = strlen(options->PskKey);
int keyLength = hexKeyLength / 2;
uint8_t * key = (uint8_t *)malloc(keyLength);
key = (uint8_t *)malloc(keyLength);
if (key)
{
char * value = options->PskKey;
Expand Down Expand Up @@ -348,6 +350,10 @@ static int Lwm2mClient_Start(Options * options)
coap_Destroy();

error_close_log:
if (key)
{
free(key);
}
Lwm2m_Info("Client exiting\n");
if (logFile)
{
Expand Down
7 changes: 7 additions & 0 deletions core/src/client/lwm2m_registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,20 @@ static void SendRegisterRequest(Lwm2mContextType * context, Lwm2mServerType * se
char serverUri[255];
char uri[1024];

if (!Lwm2mCore_IsNetworkAddressRevolved(context, server->ShortServerID))
{
Lwm2m_Debug("Registration: network address not yet revolved\n");
return;
}

if (Lwm2m_GetServerURI(context, server->ShortServerID, serverUri, sizeof(serverUri)) < 0)
{
Lwm2m_Error("Registration: Server URI is not specified\n");
server->RegistrationState = Lwm2mRegistrationState_RegisterFailed;
return;
}


GetQueryString(context, server->ShortServerID, uriQuery, sizeof(uriQuery));
Lwm2mCore_GetObjectList(context, NULL, payload, sizeof(payload), true);

Expand Down
19 changes: 18 additions & 1 deletion core/src/client/lwm2m_security_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct

char ServerURI[SERVER_URI_LEN]; //< Uniquely identifies the LWM2M server or Bootstrap server. i.e coap://host:port
AddressType address; //< Stores the host IP address and port
bool AddressResolved;
bool IsBootstrapServer;
LWM2MSecurityMode SecurityMode;
char PublicKeyIdentity[SECURITY_STRING_LEN]; //< Stores the LWM2M client certificate, public key, or PSK identity
Expand Down Expand Up @@ -349,7 +350,8 @@ static int Lwm2mSecurity_ResourceWriteHandler(void * context, ObjectIDType objec
memset(security->ServerURI, 0, sizeof(security->ServerURI));
memcpy(security->ServerURI, srcBuffer, srcBufferLen);
// Recalculate socket address from URI
result = coap_ResolveAddressByURI(security->ServerURI, &security->address);
security->AddressResolved = coap_ResolveAddressByURI(security->ServerURI, &security->address);
result = srcBufferLen;
}
else
{
Expand Down Expand Up @@ -530,6 +532,21 @@ int Lwm2m_GetServerURI(Lwm2mContextType * context, int shortServerID, char * buf
return strlen(buffer);
}

bool Lwm2mCore_IsNetworkAddressRevolved(Lwm2mContextType * context, int shortServerID)
{
bool result = false;
LWM2MSecurityInfo * security = GetSecurityInfoForShortServerID(context, shortServerID);
if (security)
{
if (!security->AddressResolved)
{
security->AddressResolved = coap_ResolveAddressByURI(security->ServerURI, &security->address);
}
result = security->AddressResolved;
}
return result;
}

int Lwm2m_GetClientHoldOff(Lwm2mContextType * context, int shortServerID, int32_t * clientHoldOff)
{
int result = -1;
Expand Down
2 changes: 2 additions & 0 deletions core/src/client/lwm2m_security_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void Lwm2m_PopulateSecurityObject(Lwm2mContextType * context, const char * bootS
int Lwm2m_GetServerURI(Lwm2mContextType * context, int shortServerID, char * buffer, int len);
int Lwm2m_GetClientHoldOff(Lwm2mContextType * context, int shortServerID, int32_t * clientHoldOff);

bool Lwm2mCore_IsNetworkAddressRevolved(Lwm2mContextType * context, int shortServerID);

bool Lwm2mCore_ServerIsBootstrap(Lwm2mContextType * context, AddressType * address);
int Lwm2mSecurity_GetShortServerID(Lwm2mContextType * context, AddressType * address);

Expand Down
18 changes: 13 additions & 5 deletions core/src/common/Makefile.common
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
common_src = \
lwm2m_list.c \
coap_abstraction_contiki.c \
network_abstraction_contiki.c \
lwm2m_debug.c \
lwm2m_util.c \
lwm2m_util_contiki.c \
lwm2m_object_store.c \
lwm2m_definition.c \
lwm2m_endpoints.c \
lwm2m_attributes.c \
lwm2m_tree_node.c \
lwm2m_endpoints.c \
lwm2m_result.c \
lwm2m_types.c \
lwm2m_attributes.c \
lwm2m_bootstrap_config.c

lwm2m_bootstrap_config.c \
coap_abstraction_erbium.c \
dtls_abstraction_dummy.c


# Below not needed for contiki
# ipc_session.c
# lwm2m_events.c
# objdefs.c

2 changes: 1 addition & 1 deletion core/src/common/coap_abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void coap_SetRequestHandler(RequestHandler handler);

int coap_WaitMessage(int timeout, int fd);

int coap_ResolveAddressByURI(unsigned char * address, AddressType * addr);
bool coap_ResolveAddressByURI(unsigned char * address, AddressType * addr);

int coap_RegisterUri(const char * uri);
int coap_DeregisterUri(const char * uri);
Expand Down
Loading

0 comments on commit c475ef2

Please sign in to comment.