* initial commit
This commit is contained in:
commit
f65ffde252
10
library.properties
Normal file
10
library.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name=Wakaama connection SAMD
|
||||||
|
version=0.1.1
|
||||||
|
author=DavidDanyi,Ericsson
|
||||||
|
maintainer=David Danyi <david.danyi@ericsson.com>
|
||||||
|
sentence=Eclipse Wakaama connection specific implementation
|
||||||
|
paragraph=
|
||||||
|
category=Communication
|
||||||
|
url=
|
||||||
|
architectures=samd
|
||||||
|
includes=
|
||||||
8
src/arduino-base.cmake
Normal file
8
src/arduino-base.cmake
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
set(ARDUINO_BASE_LIBDIR /opt/arduino-1.8.5)
|
||||||
|
set(ARDUINO_SAMD_DIR $ENV{HOME}/.arduino15/packages/arduino/hardware/samd/1.6.16)
|
||||||
|
|
||||||
|
set(ARDUINO_INCLUDE_DIRS
|
||||||
|
${ARDUINO_SAMD_DIR}/cores/arduino
|
||||||
|
${ARDUINO_SAMD_DIR}/libraries/SPI
|
||||||
|
${ARDUINO_BASE_LIBDIR}/libraries/Ethernet/src
|
||||||
|
)
|
||||||
140
src/connection.cpp
Normal file
140
src/connection.cpp
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 2014 Intel Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* The Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* David Navarro, Intel Corporation - initial API and implementation
|
||||||
|
* Pascal Rieux - Please refer to git log
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <Dns.h>
|
||||||
|
#include <Ethernet.h>
|
||||||
|
#include <IPAddress.h>
|
||||||
|
#include "connection.h"
|
||||||
|
|
||||||
|
|
||||||
|
connection_t * connection_find(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection)
|
||||||
|
{
|
||||||
|
connection_t * connP;
|
||||||
|
|
||||||
|
connP = connList;
|
||||||
|
while (connP != nullptr)
|
||||||
|
{
|
||||||
|
if (connP->udpConnection == udpConnection)
|
||||||
|
{
|
||||||
|
return connP;
|
||||||
|
}
|
||||||
|
connP = connP->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
connection_t * connection_new_incoming(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection,
|
||||||
|
IPAddress * remoteIp,
|
||||||
|
uint16_t port)
|
||||||
|
{
|
||||||
|
connection_t * connP;
|
||||||
|
|
||||||
|
connP = (connection_t *)malloc(sizeof(connection_t));
|
||||||
|
if (connP != nullptr)
|
||||||
|
{
|
||||||
|
connP->udpConnection = udpConnection;
|
||||||
|
connP->remoteIp = remoteIp;
|
||||||
|
connP->port = port;
|
||||||
|
connP->next = connList;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo add some sort of sanity checking to see if its possible to connect
|
||||||
|
* @param connList
|
||||||
|
* @param udpConnection
|
||||||
|
* @param remoteIp
|
||||||
|
* @param port
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
connection_t * connection_create(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection,
|
||||||
|
IPAddress * remoteIp,
|
||||||
|
uint16_t port)
|
||||||
|
{
|
||||||
|
connection_t * connP = nullptr;
|
||||||
|
|
||||||
|
if(*remoteIp != 0) {
|
||||||
|
connP = connection_new_incoming(connList, udpConnection, remoteIp, port);
|
||||||
|
}
|
||||||
|
return connP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void connection_free(connection_t * connList)
|
||||||
|
{
|
||||||
|
while (connList != nullptr)
|
||||||
|
{
|
||||||
|
connection_t * nextP;
|
||||||
|
|
||||||
|
nextP = connList->next;
|
||||||
|
free(connList);
|
||||||
|
|
||||||
|
connList = nextP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int connection_send(connection_t *connP,
|
||||||
|
uint8_t * buffer,
|
||||||
|
size_t length)
|
||||||
|
{
|
||||||
|
SerialOut.println(F("connection_send() start"));
|
||||||
|
connP->udpConnection->beginPacket(*(connP->remoteIp), connP->port);
|
||||||
|
connP->udpConnection->write(buffer, length);
|
||||||
|
connP->udpConnection->endPacket();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t lwm2m_buffer_send(void * sessionH,
|
||||||
|
uint8_t * buffer,
|
||||||
|
size_t length,
|
||||||
|
void * userdata)
|
||||||
|
{
|
||||||
|
auto * connP = (connection_t*) sessionH;
|
||||||
|
|
||||||
|
if (connP == nullptr)
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "#> failed sending %lu bytes, missing connection\r\n", length);
|
||||||
|
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 == connection_send(connP, buffer, length))
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "#> failed sending %lu bytes\r\n", length);
|
||||||
|
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return COAP_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool lwm2m_session_is_equal(void * session1,
|
||||||
|
void * session2,
|
||||||
|
void * userData)
|
||||||
|
{
|
||||||
|
return (session1 == session2);
|
||||||
|
}
|
||||||
61
src/connection.h
Normal file
61
src/connection.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 2014 Intel Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* The Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* David Navarro, Intel Corporation - initial API and implementation
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONNECTION_H_
|
||||||
|
#define CONNECTION_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <liblwm2m.h>
|
||||||
|
|
||||||
|
#include <EthernetUdp.h>
|
||||||
|
#include <serialout.h>
|
||||||
|
|
||||||
|
#define LWM2M_STANDARD_PORT_STR "5683"
|
||||||
|
#define LWM2M_STANDARD_PORT 5683
|
||||||
|
#define LWM2M_DTLS_PORT_STR "5684"
|
||||||
|
#define LWM2M_DTLS_PORT 5684
|
||||||
|
#define LWM2M_BSSERVER_PORT_STR "5685"
|
||||||
|
#define LWM2M_BSSERVER_PORT 5685
|
||||||
|
|
||||||
|
typedef struct _connection_t
|
||||||
|
{
|
||||||
|
struct _connection_t * next;
|
||||||
|
EthernetUDP * udpConnection;
|
||||||
|
IPAddress * remoteIp;
|
||||||
|
uint16_t port;
|
||||||
|
} connection_t;
|
||||||
|
|
||||||
|
//int create_socket(const char * portStr, int ai_family);
|
||||||
|
|
||||||
|
connection_t * connection_find(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection);
|
||||||
|
connection_t * connection_new_incoming(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection,
|
||||||
|
IPAddress * remoteIp,
|
||||||
|
uint16_t port);
|
||||||
|
connection_t * connection_create(connection_t * connList,
|
||||||
|
EthernetUDP * udpConnection,
|
||||||
|
IPAddress * remoteIp,
|
||||||
|
uint16_t port);
|
||||||
|
|
||||||
|
void connection_free(connection_t * connList);
|
||||||
|
|
||||||
|
int connection_send(connection_t *connP, uint8_t * buffer, size_t length);
|
||||||
|
|
||||||
|
#endif
|
||||||
67
src/platform.c
Normal file
67
src/platform.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 2014, 2015 Intel Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* The Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* David Navarro, Intel Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <liblwm2m.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <delay.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifndef LWM2M_MEMORY_TRACE
|
||||||
|
|
||||||
|
void * lwm2m_malloc(size_t s)
|
||||||
|
{
|
||||||
|
return malloc(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lwm2m_free(void * p)
|
||||||
|
{
|
||||||
|
return free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
char * lwm2m_strdup(const char * str)
|
||||||
|
{
|
||||||
|
return strdup(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int lwm2m_strncmp(const char * s1,
|
||||||
|
const char * s2,
|
||||||
|
size_t n)
|
||||||
|
{
|
||||||
|
return strncmp(s1, s2, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t lwm2m_gettime(void)
|
||||||
|
{
|
||||||
|
time_t seconds = floor(millis() / 1000);
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
//void lwm2m_printf(const char * format, ...)
|
||||||
|
//{
|
||||||
|
// va_list ap;
|
||||||
|
//
|
||||||
|
// va_start(ap, format);
|
||||||
|
//
|
||||||
|
// SerialUSB.println(format, ap);
|
||||||
|
//
|
||||||
|
// va_end(ap);
|
||||||
|
//}
|
||||||
29
src/shared.cmake
Normal file
29
src/shared.cmake
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Provides SHARED_SOURCES_DIR, SHARED_SOURCES, SHARED_INCLUDE_DIRS and SHARED_DEFINITIONS variables
|
||||||
|
|
||||||
|
set(SHARED_SOURCES_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||||
|
|
||||||
|
set(SHARED_SOURCES
|
||||||
|
${SHARED_SOURCES_DIR}/platform.c)
|
||||||
|
|
||||||
|
if(DTLS)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/tinydtls.cmake)
|
||||||
|
|
||||||
|
set(SHARED_SOURCES
|
||||||
|
${SHARED_SOURCES}
|
||||||
|
${TINYDTLS_SOURCES}
|
||||||
|
${SHARED_SOURCES_DIR}/dtlsconnection.c)
|
||||||
|
|
||||||
|
set(SHARED_INCLUDE_DIRS
|
||||||
|
${SHARED_SOURCES_DIR}
|
||||||
|
${TINYDTLS_SOURCES_DIR})
|
||||||
|
|
||||||
|
set(SHARED_DEFINITIONS -DWITH_TINYDTLS)
|
||||||
|
else()
|
||||||
|
set(SHARED_SOURCES
|
||||||
|
${SHARED_SOURCES}
|
||||||
|
${SHARED_SOURCES_DIR}/connection.cpp)
|
||||||
|
|
||||||
|
set(SHARED_INCLUDE_DIRS ${SHARED_SOURCES_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user