Skip to content

Commit

Permalink
Feature/lwm2m modernization (#9)
Browse files Browse the repository at this point in the history
* update the mbedtls

* Updating connection system

* moving towards zig connection handling

* Removing unused code

* Update the network and connection services

* Update the select rx enqueue

* Updating the wait subsystem
  • Loading branch information
FranciscoLlobet authored Feb 10, 2024
1 parent 7f6e9bc commit e2d4e7f
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 741 deletions.
1 change: 0 additions & 1 deletion build_mbedtls.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const source_path = [_][]const u8{
base_src_path ++ "ssl_tls13_client.c",
base_src_path ++ "ssl_tls13_generic.c",
"csrc/src/mbedtls_adapter/entropy.c",
"csrc/src/mbedtls_adapter/gmttime.c",
"csrc/src/mbedtls_adapter/timing.c",
"csrc/src/mbedtls_adapter/treading.c",
};
Expand Down
1 change: 0 additions & 1 deletion build_wakaama.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const source_path = [_][]const u8{
usr_src_path ++ "memtrace.c",
usr_src_path ++ "connection.c",
//usr_src_path ++ "commandline.c",
usr_src_path ++ "lightclient/mbedtls_connector.c",
usr_src_path ++ "lightclient/object_accelerometer.c",
usr_src_path ++ "lightclient/object_device_capability.c",
usr_src_path ++ "lightclient/object_device.c",
Expand Down
224 changes: 0 additions & 224 deletions csrc/inc/miso_mqtt_pal.h

This file was deleted.

5 changes: 1 addition & 4 deletions csrc/inc/wifi_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@

#include "miso.h"

#include "network.h"

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"



int enqueue_select_rx(enum wifi_socket_id_e id, uint32_t timeout_s);
int enqueue_select_tx(enum wifi_socket_id_e id, uint32_t timeout_s);




Expand Down
46 changes: 12 additions & 34 deletions csrc/src/lwm2m/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@
#include "mbedtls/net_sockets.h"
#include <sys/types.h>

#define SIMPLE_LINK_MAX_SEND_MTU 1472

extern mbedtls_ssl_context ssl_context;

connection_t connection_create(connection_t connList, char *host, char *port,
int protocol)
connection_t connection_create(connection_t connList, void * ctx)
{
int ret = UISO_NETWORK_GENERIC_ERROR;
int ret = -1;
connection_t newConn = lwm2m_malloc(sizeof(struct connection_s));
if(NULL != newConn)
{
ret = miso_create_network_connection(miso_get_network_ctx(wifi_service_lwm2m_socket), host, strlen(host), atoi(port), 0, (enum miso_protocol)protocol);
ret = 1;
if(ret >= 0)
{
/* Prepare */
newConn->ctx = miso_get_network_ctx(wifi_service_lwm2m_socket);
//newConn->ctx = miso_get_network_ctx(wifi_service_lwm2m_socket);
newConn->parent = ctx;
newConn->next = NULL;

if(NULL != connList)
Expand All @@ -64,17 +60,12 @@ connection_t connection_create(connection_t connList, char *host, char *port,

void connection_free(connection_t connList)
{
int ret = UISO_NETWORK_OK;
if(connList != NULL)
{
do{
// connection free
ret = miso_close_network_connection(connList->ctx);
if(ret != UISO_NETWORK_OK)
{
printf("Error: %d\n\r");
}

lwm2mservice_close_connection(connList->parent);

if(NULL != connList->next)
{
connList = connList->next;
Expand All @@ -84,37 +75,24 @@ void connection_free(connection_t connList)
}
}

int connection_send(connection_t connP, uint8_t *buffer, size_t length)
{
(void)connP;

int nbSent = miso_network_send(miso_get_network_ctx(wifi_service_lwm2m_socket), buffer, length);
if(0 > nbSent)
{
return -1;
}
return nbSent;
}


uint8_t lwm2m_buffer_send(void *sessionH, uint8_t *buffer, size_t length,
void *userdata)
{
connection_t connP = (connection_t) sessionH;
int ret = COAP_NO_ERROR;

(void) userdata; /* unused */

if (connP == NULL)
{
return COAP_500_INTERNAL_SERVER_ERROR ;
ret = COAP_500_INTERNAL_SERVER_ERROR ;
}

if (-1 == connection_send(connP, buffer, length))
else if(-1 == lwm2mservice_send_data(connP->parent, buffer, length))
{
return COAP_500_INTERNAL_SERVER_ERROR ;
ret = COAP_500_INTERNAL_SERVER_ERROR ;
}

return COAP_NO_ERROR ;
return ret;
}

bool lwm2m_session_is_equal(void *session1, void *session2, void *userData)
Expand Down
18 changes: 10 additions & 8 deletions csrc/src/lwm2m/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <stdio.h>
#include <unistd.h>
#include "network.h"
#include <sys/stat.h>
#include <liblwm2m.h>

Expand All @@ -36,17 +35,20 @@ typedef struct connection_s *connection_t;
struct connection_s
{
connection_t next;
miso_network_ctx_t ctx;
void * parent; // parent ptr
};

connection_t connection_find(connection_t connList, struct sockaddr_in *addr, size_t addrLen);
connection_t connection_new_incoming(connection_t connList,
struct miso_mbedtls_context_s *connection);
//connection_t connection_find(connection_t connList, struct sockaddr_in *addr, size_t addrLen);
//connection_t connection_new_incoming(connection_t connList,
// struct miso_mbedtls_context_s *connection);

connection_t connection_create(connection_t connList, char *host, char *port, int protocol);
connection_t connection_create(connection_t connList, void * ctx);

void connection_free(connection_t connList);

int connection_send(connection_t connP, uint8_t *buffer, size_t length);

extern int lwm2mservice_create_connection(void * conn, uint8_t * uri, uint16_t local_port, lwm2m_object_t * lwm2m_object, uint16_t sec_obj_inst_id);
extern void lwm2mservice_close_connection(void * conn);
extern int lwm2mservice_send_data(void * conn, uint8_t * buffer, size_t length);
extern int lwm2mservice_read_data(void * conn, uint8_t * buffer, size_t length);
extern int lwm2mservice_wait_data(void * conn, uint32_t timeout);
#endif
Loading

0 comments on commit e2d4e7f

Please sign in to comment.