iot/zoap: Add port information to network addresses
uIP keeps the port separated from the IP addresses, so if the application wants to communicate with a remote endpoint we must also have the port information available. Change-Id: I8e2b01fe5717166e1f9cebcc74b2056325b8ccc3 Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
This commit is contained in:
parent
92a79f7351
commit
441d22a371
4 changed files with 37 additions and 17 deletions
|
@ -530,8 +530,8 @@ static zoap_method_t method_from_code(const struct zoap_resource *resource,
|
||||||
}
|
}
|
||||||
|
|
||||||
int zoap_handle_request(struct zoap_packet *pkt,
|
int zoap_handle_request(struct zoap_packet *pkt,
|
||||||
struct zoap_resource *resources,
|
struct zoap_resource *resources,
|
||||||
const void *from)
|
const uip_ipaddr_t *addr, uint16_t port)
|
||||||
{
|
{
|
||||||
struct zoap_resource *resource;
|
struct zoap_resource *resource;
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ int zoap_handle_request(struct zoap_packet *pkt,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return method(resource, pkt, from);
|
return method(resource, pkt, addr, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
@ -587,7 +587,8 @@ static int get_observe_option(const struct zoap_packet *pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct zoap_reply *zoap_response_received(
|
struct zoap_reply *zoap_response_received(
|
||||||
const struct zoap_packet *response, const void *from,
|
const struct zoap_packet *response,
|
||||||
|
const uip_ipaddr_t *addr, uint16_t port,
|
||||||
struct zoap_reply *replies, size_t len)
|
struct zoap_reply *replies, size_t len)
|
||||||
{
|
{
|
||||||
struct zoap_reply *r;
|
struct zoap_reply *r;
|
||||||
|
@ -621,7 +622,7 @@ struct zoap_reply *zoap_response_received(
|
||||||
r->age = age;
|
r->age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->reply(response, r, from);
|
r->reply(response, r, addr, port);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,8 @@ struct zoap_resource;
|
||||||
*/
|
*/
|
||||||
typedef int (*zoap_method_t)(struct zoap_resource *resource,
|
typedef int (*zoap_method_t)(struct zoap_resource *resource,
|
||||||
struct zoap_packet *request,
|
struct zoap_packet *request,
|
||||||
const void *from);
|
const uip_ipaddr_t *addr,
|
||||||
|
uint16_t port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of the callback being called when a resource's has observers to be
|
* Type of the callback being called when a resource's has observers to be
|
||||||
|
@ -199,7 +200,9 @@ struct zoap_packet {
|
||||||
* a pending request.
|
* a pending request.
|
||||||
*/
|
*/
|
||||||
typedef int (*zoap_reply_t)(const struct zoap_packet *response,
|
typedef int (*zoap_reply_t)(const struct zoap_packet *response,
|
||||||
struct zoap_reply *reply, const void *from);
|
struct zoap_reply *reply,
|
||||||
|
const uip_ipaddr_t *addr,
|
||||||
|
uint16_t port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request awaiting for an acknowledgment (ACK).
|
* Represents a request awaiting for an acknowledgment (ACK).
|
||||||
|
@ -313,7 +316,8 @@ struct zoap_pending *zoap_pending_received(
|
||||||
* that response.
|
* that response.
|
||||||
*/
|
*/
|
||||||
struct zoap_reply *zoap_response_received(
|
struct zoap_reply *zoap_response_received(
|
||||||
const struct zoap_packet *response, const void *from,
|
const struct zoap_packet *response,
|
||||||
|
const uip_ipaddr_t *addr, uint16_t port,
|
||||||
struct zoap_reply *replies, size_t len);
|
struct zoap_reply *replies, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -345,8 +349,8 @@ void zoap_reply_clear(struct zoap_reply *reply);
|
||||||
* matching resources.
|
* matching resources.
|
||||||
*/
|
*/
|
||||||
int zoap_handle_request(struct zoap_packet *pkt,
|
int zoap_handle_request(struct zoap_packet *pkt,
|
||||||
struct zoap_resource *resources,
|
struct zoap_resource *resources,
|
||||||
const void *from);
|
const uip_ipaddr_t *addr, uint16_t port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that this resource was updated and that the @a notify callback
|
* Indicates that this resource was updated and that the @a notify callback
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <misc/byteorder.h>
|
||||||
#include <misc/nano_work.h>
|
#include <misc/nano_work.h>
|
||||||
#include <net/net_core.h>
|
#include <net/net_core.h>
|
||||||
#include <net/net_socket.h>
|
#include <net/net_socket.h>
|
||||||
|
@ -58,7 +59,9 @@ static void msg_dump(const char *s, uint8_t *data, unsigned len)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resource_reply_cb(const struct zoap_packet *response,
|
static int resource_reply_cb(const struct zoap_packet *response,
|
||||||
struct zoap_reply *reply, const void *from)
|
struct zoap_reply *reply,
|
||||||
|
const uip_ipaddr_t *addr,
|
||||||
|
uint16_t port)
|
||||||
{
|
{
|
||||||
struct net_buf *buf = response->buf;
|
struct net_buf *buf = response->buf;
|
||||||
|
|
||||||
|
@ -76,6 +79,8 @@ static void udp_receive(void)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
struct uip_conn *conn;
|
||||||
|
|
||||||
buf = net_receive(receive_context, TICKS_UNLIMITED);
|
buf = net_receive(receive_context, TICKS_UNLIMITED);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -87,13 +92,17 @@ static void udp_receive(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = uip_conn(buf);
|
||||||
|
|
||||||
pending = zoap_pending_received(&response, pendings,
|
pending = zoap_pending_received(&response, pendings,
|
||||||
NUM_PENDINGS);
|
NUM_PENDINGS);
|
||||||
if (pending) {
|
if (pending) {
|
||||||
/* If necessary cancel retransmissions */
|
/* If necessary cancel retransmissions */
|
||||||
}
|
}
|
||||||
|
|
||||||
reply = zoap_response_received(&response, buf,
|
reply = zoap_response_received(&response,
|
||||||
|
&conn->ripaddr,
|
||||||
|
sys_be16_to_cpu(conn->rport),
|
||||||
replies, NUM_REPLIES);
|
replies, NUM_REPLIES);
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
printf("No handler for response (%d)\n", r);
|
printf("No handler for response (%d)\n", r);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
#include <misc/byteorder.h>
|
||||||
#include <net/net_core.h>
|
#include <net/net_core.h>
|
||||||
#include <net/net_socket.h>
|
#include <net/net_socket.h>
|
||||||
#include <net/ip_buf.h>
|
#include <net/ip_buf.h>
|
||||||
|
@ -42,10 +43,10 @@ char fiberStack[STACKSIZE];
|
||||||
static struct net_context *context;
|
static struct net_context *context;
|
||||||
|
|
||||||
static int test_get(struct zoap_resource *resource,
|
static int test_get(struct zoap_resource *resource,
|
||||||
struct zoap_packet *request,
|
struct zoap_packet *request,
|
||||||
const void *from)
|
const uip_ipaddr_t *addr,
|
||||||
|
uint16_t port)
|
||||||
{
|
{
|
||||||
struct net_context *ctx = (struct net_context *) from;
|
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type;
|
uint8_t *payload, code, type;
|
||||||
|
@ -93,7 +94,7 @@ static int test_get(struct zoap_resource *resource,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return net_reply(ctx, buf);
|
return net_reply(context, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const test_path[] = { "test", NULL };
|
static const char * const test_path[] = { "test", NULL };
|
||||||
|
@ -111,6 +112,8 @@ static void udp_receive(void)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
struct uip_conn *conn;
|
||||||
|
|
||||||
buf = net_receive(context, TICKS_UNLIMITED);
|
buf = net_receive(context, TICKS_UNLIMITED);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -122,7 +125,10 @@ static void udp_receive(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = zoap_handle_request(&request, resources, context);
|
conn = uip_conn(buf);
|
||||||
|
|
||||||
|
r = zoap_handle_request(&request, resources, &conn->ripaddr,
|
||||||
|
sys_be16_to_cpu(conn->rport));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
printf("No handler for such request (%d)\n", r);
|
printf("No handler for such request (%d)\n", r);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue