Skip to content

Commit c558faf

Browse files
coap_service stuff added
Change-Id: I8a6f66b5c6b6d3ef3db73f8fb5bf4191963be790
1 parent f5e3a7d commit c558faf

File tree

9 files changed

+479
-25
lines changed

9 files changed

+479
-25
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "ns_types.h"
4+
#include "coap_service_api.h"
5+
6+
int main(void) {
7+
printf("!!!CoAP Server test!!!"); /* prints !!!Hello World!!! */
8+
9+
int8_t service_id = 0;
10+
11+
service_id = coap_service_initialize(0xff, 666, 0);
12+
13+
return EXIT_SUCCESS;
14+
}
15+

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Makefile for combined CoAP Service library
3+
#
4+
5+
# Define compiler toolchain with CC or PLATFORM variables
6+
# Example (GCC toolchains, default $CC and $AR are used)
7+
# make
8+
#
9+
# OR (Cross-compile GCC toolchain)
10+
# make PLATFORM=arm-linux-gnueabi-
11+
#
12+
# OR (ArmCC/Keil)
13+
# make CC=ArmCC AR=ArmAR
14+
#
15+
# OR (IAR-ARM)
16+
# make CC=iccarm
17+
18+
#
19+
# External sources from libService
20+
#
21+
SERVLIB_DIR := ../libService
22+
override CFLAGS += -I$(SERVLIB_DIR)/libService/
23+
#override CFLAGS += -I$(SERVLIB_DIR)/libService/platform/
24+
25+
NSDLC_DIR := ../nsdl-c
26+
override CFLAGS += -I$(NSDLC_DIR)/nsdl-c
27+
28+
EVENTLOOP_DIR := ../event-loop
29+
override CFLAGS += -I$(EVENTLOOP_DIR)/nanostack-event-loop/
30+
#override CFLAGS += -I$(EVENTLOOP_DIR)/event-loop/
31+
32+
#override CFLAGS += -I../libService/libService/
33+
#override CFLAGS += -I../nsdl-c/nsdl-c/
34+
#override CFLAGS += -I../event-loop/nanostack-event-loop/
35+
36+
LIB = libcoap-service.a
37+
38+
SRCS := \
39+
source/coap_service.c \
40+
source/coap_server.c \
41+
coap-service-nanomesh/coap_server_impl.c \
42+
43+
override CFLAGS += -DVERSION='"$(VERSION)"'
44+
45+
46+
47+
COAPSERVICE_DIR := ../coap-service
48+
override CFLAGS += -I$(COAPSERVICE_DIR)/coap-service/
49+
override CFLAGS += -I$(COAPSERVICE_DIR)/source/include/
50+
51+
#override CFLAGS += -Isource/coap-service/source/include/
52+
#override CFLAGS += -Icoap-service-nanomesh/include/
53+
54+
55+
include ../libService/toolchain_rules.mk
56+
57+
$(eval $(call generate_rules,$(LIB),$(SRCS)))
58+
59+
.PHONY: release
60+
release:
61+
7z a coap-service_$(VERSION).zip *.a *.lib include

coap-service-linux/coap_server_impl.c

Whitespace-only changes.

coap-service-mbed/coap_server_impl.c

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <stdlib.h>
2+
#include "ns_types.h"
3+
#include "eventOS_event.h"
4+
#include "eventOS_scheduler.h"
5+
#include "eventOS_event_timer.h"
6+
#include "nsdynmemLIB.h"
7+
#include "ns_list.h"
8+
#include "coap_server_impl.h"
9+
10+
#define COAP_SERVER_SERVICE_TASKLET_INIT 1
11+
#define COAP_SERVER_SERVICE_TIMER 2
12+
#define COAP_SERVER_SERVICE_TIMER_ID 1
13+
#define COAP_TIMER_UPDATE_PERIOD_IN_SECONDS 10
14+
15+
static int8_t coap_service_tasklet = -1;
16+
17+
void coap_server_service_tasklet(arm_event_s * event);
18+
19+
int8_t coap_server_start(void)
20+
{
21+
int8_t ret_val = -1;
22+
23+
ret_val = coap_server_service_tasklet_generated();
24+
25+
return ret_val;
26+
}
27+
28+
29+
static int8_t coap_server_service_tasklet_generated(void)
30+
{
31+
if(coap_service_tasklet == -1)
32+
{
33+
//coap_service_tasklet = eventOS_event_handler_create(&coap_server_service_tasklet,COAP_SERVER_SERVICE_TASKLET_INIT);
34+
}
35+
36+
return coap_service_tasklet;
37+
}
38+
39+
void coap_server_service_tasklet(arm_event_s * event)
40+
{
41+
42+
if(event->event_type == COAP_SERVER_SERVICE_TASKLET_INIT)
43+
{
44+
//We should define periodically timer service!!
45+
//eventOS_event_timer_request(COAP_SERVER_SERVICE_TIMER_ID, COAP_SERVER_SERVICE_TIMER,coap_service_tasklet, (COAP_TIMER_UPDATE_PERIOD_IN_SECONDS *1000));
46+
}
47+
else if(event->event_type == COAP_SERVER_SERVICE_TIMER)
48+
{
49+
//eventOS_event_timer_request(COAP_SERVER_SERVICE_TIMER_ID, COAP_SERVER_SERVICE_TIMER,coap_service_tasklet, (COAP_TIMER_UPDATE_PERIOD_IN_SECONDS *1000));
50+
}
51+
52+
}
53+
54+
uint16_t socket_open(uint16_t listen_port, coap_service_request_recv_cb *requst_recv_cb)
55+
{
56+
57+
return 0;
58+
}
59+
60+
void *memory_allocation(uint16_t size)
61+
{
62+
63+
64+
if(size)
65+
return malloc(size);
66+
else
67+
return 0;
68+
}
69+
70+
void memory_free(void* ptr)
71+
{
72+
73+
if(ptr)
74+
free(ptr);
75+
76+
}

coap-service/coap_service_api.h

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ extern "C" {
1313

1414
#include <string.h>
1515

16-
#include <ns_types.h>
17-
#include <sn_coap_header.h>
16+
#include "ns_types.h"
17+
#include "sn_coap_header.h"
1818

1919
/**
2020
* This interface is used in sending and receiving of CoAP messages to multicast address and receive multiple responses.
@@ -50,7 +50,7 @@ extern "C" {
5050
* \param listen_port Port that Application wants to use for communicate with coap server.
5151
* \param service_options Options of the current service.
5252
*
53-
* \return service_id
53+
* \return service_id / -1 for failure
5454
*/
5555
int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options);
5656

@@ -75,7 +75,7 @@ void coap_service_delete( int8_t service_id );
7575
*
7676
* \return Status
7777
*/
78-
typedef int (*coap_service_request_recv_cb)(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr);
78+
typedef int coap_service_request_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr);
7979

8080
/**
8181
* \brief Security service start callback
@@ -85,9 +85,9 @@ typedef int (*coap_service_request_recv_cb)(int8_t service_id, uint8_t source_ad
8585
* \param service_id Id number of the current service.
8686
* \param EUI64 64 bit global identifier
8787
*
88-
* \return Status
88+
* \return 0 for success / -1 for failure
8989
*/
90-
typedef int (*coap_service_security_start_cb)(int8_t service_id, uint8_t EUI64[static 8]);
90+
typedef int coap_service_security_start_cb(int8_t service_id, uint8_t EUI64[static 8]);
9191

9292
/**
9393
* \brief CoAP service security done callback
@@ -98,9 +98,9 @@ typedef int (*coap_service_security_start_cb)(int8_t service_id, uint8_t EUI64[s
9898
* \param EUI64 64 bit global identifier
9999
* \param keyblock Security key (40 bits)
100100
*
101-
* \return Status
101+
* \return 0 for success / -1 for failure
102102
*/
103-
typedef int (*coap_service_security_done_cb)(int8_t service_id, uint8_t EUI64[static 8], uint8_t keyblock[static 40]);
103+
typedef int coap_service_security_done_cb(int8_t service_id, uint8_t EUI64[static 8], uint8_t keyblock[static 40]);
104104

105105

106106
/**
@@ -112,7 +112,7 @@ typedef int (*coap_service_security_done_cb)(int8_t service_id, uint8_t EUI64[st
112112
* \param PSKd_ptr Pointer to PSK key.
113113
* \param PSKd_len Lenght of PSK key.
114114
*
115-
* \return Status
115+
* \return 0 for success / -1 for failure
116116
*/
117117
int coap_service_security_key_set(int8_t service_id, uint8_t EUI64[static 8], uint8_t *PSKd_ptr, uint8_t PSKd_len);
118118

@@ -124,9 +124,9 @@ int coap_service_security_key_set(int8_t service_id, uint8_t EUI64[static 8], ui
124124
* \param msg_id Id number of the current message.
125125
* \param response_ptr Pointer to CoAP header structure.
126126
*
127-
* \return Status
127+
* \return 0 for success / -1 for failure
128128
*/
129-
typedef int (*coap_service_response_recv)(uint16_t msg_id, sn_coap_hdr_s *response_ptr);
129+
typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr);
130130

131131
/**
132132
* \brief Virtual socket sent callback.
@@ -139,9 +139,9 @@ typedef int (*coap_service_response_recv)(uint16_t msg_id, sn_coap_hdr_s *respon
139139
* \param *data_ptr Pointer to the data.
140140
* \param data_len Lenght of the data.
141141
*
142-
* \return Status
142+
* \return 0 for success / -1 for failure
143143
*/
144-
typedef int (*coap_service_virtual_socket_send_cb)(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
144+
typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
145145

146146
/**
147147
* \brief Virtual socket read.
@@ -154,7 +154,7 @@ typedef int (*coap_service_virtual_socket_send_cb)(int8_t service_id, uint8_t de
154154
* \param *data_ptr Pointer to the data
155155
* \param data_len Lenght of the data
156156
*
157-
* \return ?
157+
* \return 0 for success / -1 for failure
158158
*/
159159
int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
160160

@@ -166,7 +166,7 @@ int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_
166166
* \param service_id Id number of the current service.
167167
* \param *send_method_ptr Callback to coap virtual socket.
168168
*
169-
* \return TODO
169+
* \return 0 for success / -1 for failure
170170
*/
171171
int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr);
172172

@@ -176,15 +176,29 @@ int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtu
176176
* Register application and informs CoAP services unsecure registery callback function.
177177
*
178178
* \param service_id Id number of the current service.
179-
* \param *uri Pointer to uri.
179+
* \param *uri_ptr Pointer to uri.
180180
* \param uri_len Length of uri.
181181
* \param port port that Application wants to use for communicate with coap server.
182182
* \param allowed_method Informs method that is allowed to use (used defines described above).
183183
* \param *request_recv_cb CoAP service request receive callback function pointer.
184184
*
185-
* \return TODO
185+
* \return 0 for success / -1 for failure
186186
*/
187-
int16_t coap_service_register_uri(int8_t service_id, uint16_t *uri, uint16_t uri_len, uint16_t port, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb);
187+
int8_t coap_service_register_uri(int8_t service_id, uint8_t *uri_ptr, uint16_t uri_len, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb);
188+
189+
/**
190+
* \brief Unregister unsecure callback methods to CoAP server
191+
*
192+
* Register application and informs CoAP services unsecure registery callback function.
193+
*
194+
* \param service_id Id number of the current service.
195+
* \param *uri_ptr Pointer to uri.
196+
* \param uri_len Length of uri.
197+
*
198+
* \return 0 for success / -1 for failure
199+
*/
200+
int8_t coap_service_unregister_uri(int8_t service_id, uint8_t *uri_ptr, uint16_t uri_len);
201+
188202

189203
/**
190204
* \brief Register secure callback methods to CoAP server.
@@ -195,16 +209,16 @@ int16_t coap_service_register_uri(int8_t service_id, uint16_t *uri, uint16_t uri
195209
* \param *start_ptr Callback to inform security handling is started.
196210
* \param *security_done_cb Callback to inform security handling is done.
197211
*
198-
* \return TODO
212+
* \return -1 for failure
213+
* instance_id For success (is used to identify registery)
199214
*
200-
* instance id that is used to identify registery.
201215
*/
202-
int16_t coap_service_register_uri_secure_cb_set(int8_t service_id, coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb);
216+
int8_t coap_service_register_uri_secure_cb_set(int8_t service_id, coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb);
203217

204218
/**
205-
* \brief Sends CoAP service request
219+
* \brief Sends CoAP service
206220
*
207-
* Build and sends CoAP service request message.
221+
* Build and sends CoAP service message.
208222
*
209223
* \param service_id Id number of the current service.
210224
* \param options Options defined above.
@@ -215,7 +229,30 @@ int16_t coap_service_register_uri_secure_cb_set(int8_t service_id, coap_service_
215229
*
216230
* \return msg_id Id number of the current message.
217231
*/
218-
uint16_t coap_service_request_send(int8_t service_id, uint8_t options, uint8_t addr[static 16], uint16_t destination_port, sn_coap_hdr_s *request_ptr, coap_service_response_recv *request_response_cb);
232+
uint16_t coap_service_send(int8_t service_id, uint8_t options, uint8_t addr[static 16], uint16_t destination_port, sn_coap_hdr_s *request_ptr, coap_service_response_recv *request_response_cb);
233+
234+
/**
235+
* \brief Sends CoAP service request
236+
*
237+
* Build and sends CoAP service request message.
238+
*
239+
* \param service_id Id number of the current service.
240+
* \param options Options defined above.
241+
* \param destination_addr IPv6 address.
242+
* \param destination_port Destination port
243+
* \param msg_type Message type can be found from sn_coap_header.
244+
* \param msg_code Message code can be found from sn_coap_header.
245+
* \param *uri_ptr Pointer to uri.
246+
* \param uri_len Length of uri.
247+
* \param cont_type Content type can be found from sn_coap_header.
248+
* \param payload_ptr Pointer to message content.
249+
* \param payload_len Lenght of the message.
250+
* \param *request_response_cb Callback to inform result of the request.
251+
*
252+
* \return msg_id Id number of the current message.
253+
*/
254+
uint16_t coap_service_request_send(int8_t service_id, uint8_t options, uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, uint8_t *uri_ptr, uint16_t uri_len,
255+
uint8_t cont_type, uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb);
219256

220257
/**
221258
* \brief Sends CoAP service response
@@ -227,7 +264,8 @@ uint16_t coap_service_request_send(int8_t service_id, uint8_t options, uint8_t a
227264
* \param options Options defined above.
228265
* \param response_ptr Pointer to CoAP header structure.
229266
*
230-
* \return TODO
267+
* \return -1 For failure
268+
*- 0 For success
231269
*/
232270
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type,uint8_t * payload_ptr,uint16_t payload_len);
233271

0 commit comments

Comments
 (0)