summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Santes <flavio.santes@intel.com>2016-09-09 01:14:23 -0500
committerAnas Nashif <nashif@linux.intel.com>2016-09-12 02:15:44 +0000
commit13a75b7e4284a2866b05d286cf1e51143c4dd638 (patch)
treeaaad96996e0339cfbd4ae0f5a0d9c5a14348e2a8
parentcf0efbb51f18cdb29a9187c6df1bf4922eaa703b (diff)
dns: Remove deprecated functionality
This commit removes deprecated APIs and replaces them with routines that provide similar functionality without the flexibility originally offered by the deprecated APIs. Removing deprecated routines will help us to be prepared once the new IP stack is ready (ZEP-793). Furthermore, this commit will also help us to move our current DNS Client implementation to the lib/iot directory, as specified by ZEP-847. This commit removes the netz library from the DNS client sample application. UDP functionality is replaced by primitive routines. Specifically, the following changes are applied by this patch: - Remove netz routines - Remove app_buf data structure - Introduce primitive data types in the DNS client code - Introduce primitive network routines - Add a header file containing configurable parameters Jira: ZEP-793 Jira: ZEP-847 Change-Id: I0302133da77308f0cdd9ace2c0265e6b77673ff0 Signed-off-by: Flavio Santes <flavio.santes@intel.com>
-rw-r--r--samples/net/dns_client/README12
-rw-r--r--samples/net/dns_client/README_API1
-rw-r--r--samples/net/dns_client/src/Makefile4
-rw-r--r--samples/net/dns_client/src/app_buf.h19
-rw-r--r--samples/net/dns_client/src/dns_pack.c20
-rw-r--r--samples/net/dns_client/src/dns_pack.h20
-rw-r--r--samples/net/dns_client/src/dns_utils.c7
-rw-r--r--samples/net/dns_client/src/dns_utils.h2
-rw-r--r--samples/net/dns_client/src/main.c72
-rw-r--r--samples/net/dns_client/src/netz.c222
-rw-r--r--samples/net/dns_client/src/netz.h163
-rw-r--r--samples/net/dns_client/src/tcp.c120
-rw-r--r--samples/net/dns_client/src/tcp.h26
-rw-r--r--samples/net/dns_client/src/tcp_config.h46
-rw-r--r--samples/net/dns_client/testcase.ini3
15 files changed, 250 insertions, 487 deletions
diff --git a/samples/net/dns_client/README b/samples/net/dns_client/README
index 347afa0b4..1157632d7 100644
--- a/samples/net/dns_client/README
+++ b/samples/net/dns_client/README
@@ -19,7 +19,7 @@ Requirements
Building instructions
---------------------
-* Read src/main.c, change the IP addresses according to the LAN
+* Read src/tcp_config.h, change the IP addresses according to the LAN
environment.
* make pristine && make are enough to build this sample.
@@ -137,13 +137,3 @@ Usage
Response: IP address Size: 4: 63 80 4 161
[fiber:102] DNS Response: OK
-
-
-Compiler Warnings
------------------
-
-The network layer used in this sample code will be replaced once the
-new IP stack is ready. So, "netz" is tagged as "deprecated" and the
-following warnings will be displayed by the compiler:
-
-warning: 'netz_tx' is deprecated [-Wdeprecated-declarations]
diff --git a/samples/net/dns_client/README_API b/samples/net/dns_client/README_API
index b02812e7e..db2582275 100644
--- a/samples/net/dns_client/README_API
+++ b/samples/net/dns_client/README_API
@@ -20,4 +20,3 @@ TODO
Identifier internally.
* dns_response in src/main.c once high-level functions are
available.
-
diff --git a/samples/net/dns_client/src/Makefile b/samples/net/dns_client/src/Makefile
index 62e1e96d4..95dff202c 100644
--- a/samples/net/dns_client/src/Makefile
+++ b/samples/net/dns_client/src/Makefile
@@ -19,7 +19,7 @@ ccflags-y +=-I${ZEPHYR_BASE}/net/ip/contiki/os/lib
ccflags-y +=-I${ZEPHYR_BASE}/net/ip/contiki/os
ccflags-y +=-I${ZEPHYR_BASE}/net/ip
-obj-y += dns_pack.o
-obj-y += netz.o
+obj-y += tcp.o
obj-y += dns_utils.o
+obj-y += dns_pack.o
obj-y += main.o
diff --git a/samples/net/dns_client/src/app_buf.h b/samples/net/dns_client/src/app_buf.h
deleted file mode 100644
index 72706b5e3..000000000
--- a/samples/net/dns_client/src/app_buf.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _APP_BUF_H_
-#define _APP_BUF_H_
-
-#include <zephyr.h> /* for __deprecated */
-#include <stdint.h>
-#include <stddef.h>
-
-struct __deprecated app_buf_t;
-
-struct app_buf_t {
- uint8_t *buf;
- size_t size;
- size_t length;
-};
-
-#define APP_BUF_INIT(_buf, _size, _length) {.buf = _buf, .size = _size,\
- .length = _length}
-
-#endif
diff --git a/samples/net/dns_client/src/dns_pack.c b/samples/net/dns_client/src/dns_pack.c
index ab28c5f20..453d5c797 100644
--- a/samples/net/dns_client/src/dns_pack.c
+++ b/samples/net/dns_client/src/dns_pack.c
@@ -206,38 +206,38 @@ static int dns_msg_pack_query_header(uint8_t *buf, int size, uint16_t id)
return 0;
}
-int dns_msg_pack_query(struct app_buf_t *buf, char *domain_name,
- uint16_t id, enum dns_rr_type qtype)
+int dns_msg_pack_query(uint8_t *buf, size_t *len, size_t size,
+ char *domain_name, uint16_t id, enum dns_rr_type qtype)
{
int qname_len;
int offset;
int rc;
- rc = dns_msg_pack_query_header(buf->buf, buf->size, id);
+ rc = dns_msg_pack_query_header(buf, size, id);
if (rc != 0) {
return rc;
}
offset = DNS_MSG_HEADER_SIZE;
- rc = dns_msg_pack_qname(&qname_len, buf->buf + offset,
- buf->size - offset, domain_name);
+ rc = dns_msg_pack_qname(&qname_len, buf + offset,
+ size - offset, domain_name);
if (rc != 0) {
return rc;
}
offset += qname_len;
- /* 4Bytes required: QType: (2B), QClass (2B) */
- if (offset + 4 > buf->size) {
+ /* 4 bytes required: QType: (2), QClass (2) */
+ if (offset + 4 > size) {
return rc;
}
/* QType */
- *(uint16_t *)(buf->buf + offset + 0) = sys_cpu_to_be16(qtype);
+ *(uint16_t *)(buf + offset + 0) = sys_cpu_to_be16(qtype);
/* QClass */
- *(uint16_t *)(buf->buf + offset + 2) = sys_cpu_to_be16(DNS_CLASS_IN);
+ *(uint16_t *)(buf + offset + 2) = sys_cpu_to_be16(DNS_CLASS_IN);
- buf->length = offset + 4;
+ *len = offset + 4;
return 0;
}
diff --git a/samples/net/dns_client/src/dns_pack.h b/samples/net/dns_client/src/dns_pack.h
index 2eddfc9e5..98ff8f33c 100644
--- a/samples/net/dns_client/src/dns_pack.h
+++ b/samples/net/dns_client/src/dns_pack.h
@@ -17,14 +17,12 @@
#ifndef _DNS_PACK_H_
#define _DNS_PACK_H_
+#include <misc/byteorder.h>
+
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
-#include <misc/byteorder.h>
-
-#include "app_buf.h"
-
/**
* @brief dns_msg_t
*
@@ -320,17 +318,19 @@ int dns_unpack_response_header(struct dns_msg_t *msg, int src_id);
/**
* @brief dns_msg_pack_query Packs the query message
- * @param buf Buffer that will contain the resultant query
- * @param domain_name Something like: www.example.com
- * @param id Transaction Identifier
- * @param qtype Query type: AA, AAAA. See enum dns_rr_type
+ * @param [out] buf Buffer that will contain the resultant query
+ * @param [out] len Number of bytes used to encode the query
+ * @param [in] size Buffer size
+ * @param [in] domain_name Something like: www.example.com
+ * @param [in] id Transaction Identifier
+ * @param [in] qtype Query type: AA, AAAA. See enum dns_rr_type
* @return 0 on success
* @return On error, a negative value is returned. See:
* - dns_msg_pack_query_header
* - dns_msg_pack_qname
*/
-int dns_msg_pack_query(struct app_buf_t *buf, char *domain_name,
- uint16_t id, enum dns_rr_type qtype);
+int dns_msg_pack_query(uint8_t *buf, size_t *len, size_t size,
+ char *domain_name, uint16_t id, enum dns_rr_type qtype);
/**
* @brief dns_unpack_response_query
diff --git a/samples/net/dns_client/src/dns_utils.c b/samples/net/dns_client/src/dns_utils.c
index 7441c049d..b5c152d85 100644
--- a/samples/net/dns_client/src/dns_utils.c
+++ b/samples/net/dns_client/src/dns_utils.c
@@ -151,10 +151,3 @@ int print_buf(uint8_t *buf, size_t size)
return 0;
}
-
-
-int print_app_buf(struct app_buf_t *buf)
-{
- print_buf(buf->buf, buf->length);
- return 0;
-}
diff --git a/samples/net/dns_client/src/dns_utils.h b/samples/net/dns_client/src/dns_utils.h
index 865d990e0..76e62aaff 100644
--- a/samples/net/dns_client/src/dns_utils.h
+++ b/samples/net/dns_client/src/dns_utils.h
@@ -17,7 +17,6 @@
#ifndef _DNS_UTILS_H_
#define _DNS_UTILS_H_
-#include "app_buf.h"
#include <stdint.h>
int dns_print_msg_header(uint8_t *header, int size);
@@ -25,6 +24,5 @@ int dns_print_msg_query(uint8_t *qname, int qname_size, int qtype, int qclass);
int dns_print_label(uint8_t *label, int size);
int dns_print_readable_msg_label(int offset, uint8_t *buf, int size);
int print_buf(uint8_t *buf, size_t size);
-int print_app_buf(struct app_buf_t *buf);
#endif
diff --git a/samples/net/dns_client/src/main.c b/samples/net/dns_client/src/main.c
index e69cf43ed..703bda09d 100644
--- a/samples/net/dns_client/src/main.c
+++ b/samples/net/dns_client/src/main.c
@@ -19,58 +19,52 @@
#include <string.h>
#include <errno.h>
-#include "dns_pack.h"
+#include "tcp_config.h"
+#include "tcp.h"
+
#include "dns_utils.h"
-#include "netz.h"
+#include "dns_pack.h"
#define STACK_SIZE 1024
uint8_t stack[STACK_SIZE];
#define BUF_SIZE 1024
-uint8_t tx_raw_buf[BUF_SIZE];
-uint8_t rx_raw_buf[BUF_SIZE];
+uint8_t tx_buf[BUF_SIZE];
+uint8_t rx_buf[BUF_SIZE];
-#define SLEEP_TIME 50
+size_t tx_len;
+size_t rx_len;
+
+struct net_context *ctx;
#define RC_STR(rc) (rc == 0 ? "OK" : "ERROR")
char *domains[] = {"not_a_real_domain_name",
"linuxfoundation.org", "www.linuxfoundation.org",
- "gnu.org", "www.gnu.org",
- "npr.org", "www.npr.org",
"wikipedia.org", "www.wikipedia.org",
"zephyrproject.org", "www.zephyrproject.org",
NULL};
/* this function creates the DNS query */
-int dns_query(struct app_buf_t *buf, char *str, uint16_t id,
- enum dns_rr_type qtype);
+int dns_query(uint8_t *buf, size_t *len, size_t size,
+ char *str, uint16_t id, enum dns_rr_type qtype);
/* this function parses the DNS server response */
-int dns_response(struct app_buf_t *_buf, int *response_type, int src_id);
+int dns_response(uint8_t *buf, size_t size, int *response_type, int src_id);
void fiber(void)
{
- struct app_buf_t tx_buf = APP_BUF_INIT(tx_raw_buf,
- sizeof(tx_raw_buf), 0);
-
- struct app_buf_t rx_buf = APP_BUF_INIT(rx_raw_buf,
- sizeof(rx_raw_buf), 0);
-
- /* If the network is a bit slow, increase rx_timeout and
- * tx_retry_timeout in struct netz_ctx_t
- */
- struct netz_ctx_t netz_ctx = NETZ_CTX_INIT;
-
int response_type;
int counter;
char *name;
int rc;
- netz_host_ipv4(&netz_ctx, 192, 168, 1, 101);
- netz_remote_ipv4(&netz_ctx, 192, 168, 1, 10, 5353);
- netz_netmask_ipv4(&netz_ctx, 255, 255, 255, 0);
- netz_udp(&netz_ctx);
+ rc = tcp_init(&ctx);
+ if (rc != 0) {
+ printk("[%s:%d] Unable to init net_context\n",
+ __func__, __LINE__);
+ return;
+ }
counter = 0;
do {
@@ -84,27 +78,29 @@ void fiber(void)
printf("Domain name: %s\n", name);
- rc = dns_query(&tx_buf, name, counter, DNS_RR_TYPE_A);
+ rc = dns_query(tx_buf, &tx_len, sizeof(tx_buf), name, counter,
+ DNS_RR_TYPE_A);
printf("[%s:%d] DNS Query: %s, ID: %d\n",
__func__, __LINE__, RC_STR(rc), counter);
- rc = netz_tx(&netz_ctx, &tx_buf);
+ rc = tcp_tx(ctx, tx_buf, tx_len);
printf("[%s:%d] TX: %s\n", __func__, __LINE__, RC_STR(rc));
- fiber_sleep(SLEEP_TIME);
+ fiber_sleep(APP_SLEEP_TICKS);
- rc = netz_rx(&netz_ctx, &rx_buf);
+ rc = tcp_rx(ctx, rx_buf, &rx_len, sizeof(rx_buf));
printf("[%s:%d] RX: %s\n", __func__, __LINE__, RC_STR(rc));
if (rc == 0) {
- rc = dns_response(&rx_buf, &response_type, counter);
+ rc = dns_response(rx_buf, rx_len,
+ &response_type, counter);
printf("[%s:%d] DNS Response: %s %s\n",
__func__, __LINE__, RC_STR(rc),
(rc != 0 && counter == 0 ? "<- :)" : ""));
}
counter += 1;
- fiber_sleep(SLEEP_TIME);
+ fiber_sleep(APP_SLEEP_TICKS);
} while (1);
}
@@ -118,10 +114,10 @@ void main(void)
}
/* Next versions must handle the transaction id internally */
-int dns_query(struct app_buf_t *buf, char *str, uint16_t id,
- enum dns_rr_type qtype)
+int dns_query(uint8_t *buf, size_t *len, size_t size,
+ char *str, uint16_t id, enum dns_rr_type qtype)
{
- return dns_msg_pack_query(buf, str, id, qtype);
+ return dns_msg_pack_query(buf, len, size, str, id, qtype);
}
/* See dns_unpack_answer, and also see:
@@ -129,9 +125,9 @@ int dns_query(struct app_buf_t *buf, char *str, uint16_t id,
*/
#define DNS_QUERY_POS 0x0c
-int dns_response(struct app_buf_t *_buf, int *response_type, int src_id)
+int dns_response(uint8_t *buf, size_t size, int *response_type, int src_id)
{
- struct dns_msg_t dns_msg = DNS_MSG_INIT(_buf->buf, _buf->size);
+ struct dns_msg_t dns_msg = DNS_MSG_INIT(buf, size);
int ptr;
int rc;
int i;
@@ -187,8 +183,8 @@ int dns_response(struct app_buf_t *_buf, int *response_type, int src_id)
break;
}
- dns_msg.answer_offset = dns_msg.answer_offset + 12
- + dns_msg.response_length;
+ dns_msg.answer_offset = dns_msg.answer_offset + 12 +
+ dns_msg.response_length;
++i;
}
diff --git a/samples/net/dns_client/src/netz.c b/samples/net/dns_client/src/netz.c
deleted file mode 100644
index b555fa85e..000000000
--- a/samples/net/dns_client/src/netz.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "netz.h"
-
-#include <net/net_core.h>
-#include <net/net_socket.h>
-
-#include <string.h>
-#include <errno.h>
-
-void netz_host(struct netz_ctx_t *ctx, struct net_addr *host)
-{
- return netz_host_ipv4(ctx, host->in_addr.in4_u.u4_addr8[0],
- host->in_addr.in4_u.u4_addr8[1],
- host->in_addr.in4_u.u4_addr8[2],
- host->in_addr.in4_u.u4_addr8[3]);
-}
-
-void netz_host_ipv4(struct netz_ctx_t *ctx, uint8_t a1, uint8_t a2,
- uint8_t a3, uint8_t a4)
-{
- uip_ipaddr_t host_addr;
-
- uip_ipaddr(&host_addr, a1, a2, a3, a4);
- uip_sethostaddr(&host_addr);
-
- ctx->host.in_addr.in4_u.u4_addr8[0] = a1;
- ctx->host.in_addr.in4_u.u4_addr8[1] = a2;
- ctx->host.in_addr.in4_u.u4_addr8[2] = a3;
- ctx->host.in_addr.in4_u.u4_addr8[3] = a4;
- ctx->host.family = AF_INET;
-}
-
-void netz_netmask(struct netz_ctx_t *ctx, struct net_addr *netmask)
-{
- return netz_netmask_ipv4(ctx, netmask->in_addr.in4_u.u4_addr8[0],
- netmask->in_addr.in4_u.u4_addr8[1],
- netmask->in_addr.in4_u.u4_addr8[2],
- netmask->in_addr.in4_u.u4_addr8[3]);
-}
-
-void netz_netmask_ipv4(struct netz_ctx_t *ctx, uint8_t n1, uint8_t n2,
- uint8_t n3, uint8_t n4)
-{
- ARG_UNUSED(ctx);
-
- uip_ipaddr_t netmask;
-
- uip_ipaddr(&netmask, n1, n2, n3, n4);
- uip_setnetmask(&netmask);
-}
-
-void netz_remote(struct netz_ctx_t *ctx, struct net_addr *remote, int port)
-{
- return netz_remote_ipv4(ctx, remote->in_addr.in4_u.u4_addr8[0],
- remote->in_addr.in4_u.u4_addr8[1],
- remote->in_addr.in4_u.u4_addr8[2],
- remote->in_addr.in4_u.u4_addr8[3], port);
-}
-
-void netz_remote_ipv4(struct netz_ctx_t *ctx, uint8_t a1, uint8_t a2,
- uint8_t a3, uint8_t a4, int port)
-{
- ctx->remote.in_addr.in4_u.u4_addr8[0] = a1;
- ctx->remote.in_addr.in4_u.u4_addr8[1] = a2;
- ctx->remote.in_addr.in4_u.u4_addr8[2] = a3;
- ctx->remote.in_addr.in4_u.u4_addr8[3] = a4;
- ctx->remote.family = AF_INET;
-
- ctx->remote_port = port;
-}
-
-static int netz_prepare(struct netz_ctx_t *ctx, enum ip_protocol proto)
-{
-#ifdef CONFIG_NETWORKING_WITH_TCP
- struct app_buf_t buf = APP_BUF_INIT(NULL, 0, 0);
- int rc;
-#endif
-
- ctx->connected = 0;
- ctx->proto = proto;
-
- ctx->net_ctx = net_context_get(ctx->proto,
- &ctx->remote, ctx->remote_port,
- &ctx->host, 0);
- if (ctx->net_ctx == NULL) {
- return -EINVAL;
- }
-
-#ifdef CONFIG_NETWORKING_WITH_TCP
- /* workaround to activate the IP stack */
- rc = netz_tx(ctx, &buf);
- if (rc != 0) {
- return rc;
- }
-#endif
- ctx->connected = 1;
- return 0;
-}
-
-int netz_tcp(struct netz_ctx_t *ctx)
-{
- return netz_prepare(ctx, IPPROTO_TCP);
-}
-
-int netz_udp(struct netz_ctx_t *ctx)
-{
- return netz_prepare(ctx, IPPROTO_UDP);
-}
-
-static void netz_sleep(int sleep_ticks)
-{
- struct nano_timer timer;
-
- nano_timer_init(&timer, NULL);
- nano_fiber_timer_start(&timer, sleep_ticks);
- nano_fiber_timer_test(&timer, TICKS_UNLIMITED);
-}
-
-static int tcp_tx(struct net_context *ctx, uint8_t *buf, size_t size,
- int tx_retry_timeout)
-{
- struct net_buf *nbuf;
- uint8_t *ptr;
- int rc;
-
- nbuf = ip_buf_get_tx(ctx);
- if (nbuf == NULL) {
- return -EINVAL;
- }
-
- ptr = net_buf_add(nbuf, size);
- memcpy(ptr, buf, size);
- ip_buf_appdatalen(nbuf) = size;
-
- do {
- rc = net_send(nbuf);
-
- if (rc >= 0) {
- return 0;
- }
- switch (rc) {
- case -EINPROGRESS:
- netz_sleep(tx_retry_timeout);
- break;
- case -EAGAIN:
- case -ECONNRESET:
- netz_sleep(tx_retry_timeout);
- break;
- default:
- ip_buf_unref(nbuf);
- return -EIO;
- }
- } while (1);
-
- return -EIO;
-}
-
-static int tcp_rx(struct net_context *ctx, uint8_t *buf, size_t *read_bytes,
- size_t size, int rx_timeout)
-{
- struct net_buf *nbuf;
- int rc;
-
- nbuf = net_receive(ctx, rx_timeout);
- if (nbuf == NULL) {
- return -EIO;
- }
-
- *read_bytes = ip_buf_appdatalen(nbuf);
- if (*read_bytes > size) {
- *read_bytes = size;
- rc = -ENOMEM;
- } else {
- rc = 0;
- }
-
- memcpy(buf, ip_buf_appdata(nbuf), *read_bytes);
- ip_buf_unref(nbuf);
-
- return rc;
-}
-
-int netz_tx(struct netz_ctx_t *ctx, struct app_buf_t *buf)
-{
- int rc;
-
- /* We don't evaluate if we are connected. */
-
- rc = tcp_tx(ctx->net_ctx, buf->buf, buf->length,
- ctx->tx_retry_timeout);
-
- return rc;
-}
-
-int netz_rx(struct netz_ctx_t *ctx, struct app_buf_t *buf)
-{
- int rc;
-
- if (ctx->connected != 1) {
- return -ENOTCONN;
- }
-
- rc = tcp_rx(ctx->net_ctx, buf->buf, &buf->length, buf->size,
- ctx->rx_timeout);
-
- return rc;
-}
diff --git a/samples/net/dns_client/src/netz.h b/samples/net/dns_client/src/netz.h
deleted file mode 100644
index 3830b9a56..000000000
--- a/samples/net/dns_client/src/netz.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _NETZ_H_
-#define _NETZ_H_
-
-#include <net/ip_buf.h>
-#include <net/net_core.h>
-
-#include "app_buf.h"
-
-struct __deprecated netz_ctx_t;
-
-struct netz_ctx_t {
- struct net_context *net_ctx;
- int connected;
-
- int rx_timeout;
- int tx_retry_timeout;
-
- struct net_addr host;
- int host_port;
-
- struct net_addr remote;
- int remote_port;
-
- enum ip_protocol proto;
-};
-
-#define TCP_COMMON_TIMEOUT 20
-
-/**
- * @brief NETZ_CTX_INIT Initializes a netz context with default values
- */
-#define NETZ_CTX_INIT { .rx_timeout = TCP_COMMON_TIMEOUT, \
- .tx_retry_timeout = TCP_COMMON_TIMEOUT, \
- .net_ctx = NULL, \
- .connected = 0, \
- .proto = IPPROTO_UDP, \
- .host_port = 0, \
- .remote_port = 0}
-
-/**
- * @brief NET_ADDR_IPV4_INIT Initializes a net_addr structure with
- * an IPv4 address specified by a1, a2, a3 and a4
- */
-#define NET_ADDR_IPV4_INIT(a1, a2, a3, a4) {.in_addr.in4_u.u4_addr8[0] = (a1),\
- .in_addr.in4_u.u4_addr8[1] = (a2),\
- .in_addr.in4_u.u4_addr8[2] = (a3),\
- .in_addr.in4_u.u4_addr8[3] = (a4),\
- .family = AF_INET}
-
-/**
- * @brief netz_host Sets the host IPv4 address (no IPv6 support)
- * @param ctx netz context structure
- * @param host Network address
- */
-void __deprecated netz_host(struct netz_ctx_t *ctx, struct net_addr *host);
-
-/**
- * @brief netz_host_ipv4 Sets the host IPv4 address (no IPv6 support)
- * @param ctx netz context structure
- * @param a1 Byte 0 of the IPv4 address
- * @param a2 Byte 1 of the IPv4 address
- * @param a3 Byte 2 of the IPv4 address
- * @param a4 Byte 3 of the IPv4 address
- */
-void __deprecated netz_host_ipv4(struct netz_ctx_t *ctx, uint8_t a1,
- uint8_t a2, uint8_t a3, uint8_t a4);
-
-/**
- * @brief netz_netmask Sets the host's netmask address
- * @param ctx netz context structure
- * @param netmask Network address to be used as netmask
- */
-void __deprecated netz_netmask(struct netz_ctx_t *ctx,
- struct net_addr *netmask);
-
-/**
- * @brief netz_netmask_ipv4 Sets the host's netmask IPv4 address
- * @param ctx netz context structure
- * @param n1 Byte 0 of the IPv4 address
- * @param n2 Byte 1 of the IPv4 address
- * @param n3 Byte 2 of the IPv4 address
- * @param n4 Byte 3 of the IPv4 address
- */
-void __deprecated netz_netmask_ipv4(struct netz_ctx_t *ctx, uint8_t n1,
- uint8_t n2, uint8_t n3, uint8_t n4);
-/**
- * @brief netz_remote Sets the address of the remote peer
- * @param ctx netz context structure
- * @param remote Network address of the remote peer
- * @param port Port number of the remote peer
- */
-void __deprecated netz_remote(struct netz_ctx_t *ctx, struct net_addr *remote,
- int port);
-
-/**
- * @brief netz_remote_ipv4 Sets the IPv4 address of the remote peer
- * @param ctx netz context structure
- * @param a1 Byte 0 of the IPv4 address
- * @param a2 Byte 1 of the IPv4 address
- * @param a3 Byte 2 of the IPv4 address
- * @param a4 Byte 3 of the IPv4 address
- */
-
-void __deprecated netz_remote_ipv4(struct netz_ctx_t *ctx, uint8_t a1,
- uint8_t a2, uint8_t a3, uint8_t a4,
- int port);
-
-/**
- * @brief netz_tcp Initializes the netz context & connects
- * to the remote peer
- * @param ctx netz context structure
- * @return 0 on success
- * @return -EINVAL if a null context was obtained
- * @return Read netz_tx return codes
- */
-int __deprecated netz_tcp(struct netz_ctx_t *ctx);
-
-/**
- * @brief netz_udp Initializes the context for UDP transfers
- * @param ctx netz context structure
- * @return 0 on success
- * @return -EINVAL if a null context was obtained
- */
-int __deprecated netz_udp(struct netz_ctx_t *ctx);
-
-/**
- * @brief netz_tx TCP/UDP data transmission
- * @param ctx netz context structure
- * @param buf Buffer that contains the data to be sent
- * @return 0 on success
- * @return -EINVAL if no network buffer is available
- * @return -EIO if a TCP error was detected
- */
-int __deprecated netz_tx(struct netz_ctx_t *ctx, struct app_buf_t *buf);
-
-/**
- * @brief netz_rx TCP/UDP data reception
- * @param ctx netz context structure
- * @param buf Buffer that contains the received data
- * @return 0 on success
- * @return -EIO on TCP or network buffer error
- * @return -ENOMEM if the space in buf is not enough
- * to store the received data
- */
-int __deprecated netz_rx(struct netz_ctx_t *ctx, struct app_buf_t *buf);
-
-#endif
diff --git a/samples/net/dns_client/src/tcp.c b/samples/net/dns_client/src/tcp.c
new file mode 100644
index 000000000..f33dfd416
--- /dev/null
+++ b/samples/net/dns_client/src/tcp.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tcp_config.h"
+#include "tcp.h"
+
+#include <string.h>
+#include <errno.h>
+
+#include <net/net_socket.h>
+#include <net/net_core.h>
+#include <net/ip_buf.h>
+
+uip_ipaddr_t uip_hostaddr = { { CLIENT_IPADDR0, CLIENT_IPADDR1,
+ CLIENT_IPADDR2, CLIENT_IPADDR3 } };
+
+uip_ipaddr_t uip_netmask = { { NETMASK0, NETMASK1, NETMASK2, NETMASK3 } };
+
+
+#define CLIENT_IP_ADDR { { { CLIENT_IPADDR0, CLIENT_IPADDR1, \
+ CLIENT_IPADDR2, CLIENT_IPADDR3 } } }
+
+#define SERVER_IP_ADDR { { { SERVER_IPADDR0, SERVER_IPADDR1, \
+ SERVER_IPADDR2, SERVER_IPADDR3 } } }
+
+#define INET_FAMILY AF_INET
+
+int tcp_tx(struct net_context *ctx, uint8_t *buf, size_t size)
+{
+ struct net_buf *nbuf = NULL;
+ uint8_t *ptr;
+ int rc = 0;
+
+ nbuf = ip_buf_get_tx(ctx);
+ if (nbuf == NULL) {
+ return -EINVAL;
+ }
+
+ ptr = net_buf_add(nbuf, size);
+ memcpy(ptr, buf, size);
+ ip_buf_appdatalen(nbuf) = size;
+
+ do {
+ rc = net_send(nbuf);
+ if (rc >= 0) {
+ return 0;
+ }
+ switch (rc) {
+ case -EINPROGRESS:
+ fiber_sleep(TCP_RETRY_TIMEOUT);
+ break;
+ case -EAGAIN:
+ case -ECONNRESET:
+ fiber_sleep(TCP_RETRY_TIMEOUT);
+ break;
+ default:
+ ip_buf_unref(nbuf);
+ return -EIO;
+ }
+ } while (1);
+
+ return 0;
+}
+
+int tcp_rx(struct net_context *ctx, uint8_t *buf, size_t *len, size_t size)
+{
+ struct net_buf *nbuf;
+ int rc = 0;
+
+ nbuf = net_receive(ctx, TCP_RX_TIMEOUT);
+ if (nbuf == NULL) {
+ return -EIO;
+ }
+
+ *len = ip_buf_appdatalen(nbuf);
+ if (*len > size) {
+ *len = size;
+ rc = -ENOMEM;
+ }
+
+ memcpy(buf, ip_buf_appdata(nbuf), *len);
+ ip_buf_unref(nbuf);
+
+ return rc;
+}
+
+int tcp_init(struct net_context **ctx)
+{
+ static struct in_addr server_addr = SERVER_IP_ADDR;
+ static struct in_addr client_addr = CLIENT_IP_ADDR;
+ static struct net_addr server;
+ static struct net_addr client;
+
+ server.in_addr = server_addr;
+ server.family = AF_INET;
+
+ client.in_addr = client_addr;
+ client.family = AF_INET;
+
+ *ctx = net_context_get(APP_PROTOCOL,
+ &server, SERVER_PORT,
+ &client, CLIENT_PORT);
+ if (*ctx == NULL) {
+ return -EINVAL;
+ }
+ return 0;
+}
diff --git a/samples/net/dns_client/src/tcp.h b/samples/net/dns_client/src/tcp.h
new file mode 100644
index 000000000..ac193846a
--- /dev/null
+++ b/samples/net/dns_client/src/tcp.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _TCP_H_
+#define _TCP_H_
+
+#include <net/net_core.h>
+
+int tcp_init(struct net_context **ctx);
+int tcp_tx(struct net_context *ctx, uint8_t *buf, size_t size);
+int tcp_rx(struct net_context *ctx, uint8_t *buf, size_t *len, size_t size);
+
+#endif
diff --git a/samples/net/dns_client/src/tcp_config.h b/samples/net/dns_client/src/tcp_config.h
new file mode 100644
index 000000000..45ee83aac
--- /dev/null
+++ b/samples/net/dns_client/src/tcp_config.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _TCP_CONFIG_H_
+#define _TCP_CONFIG_H_
+
+#include <net/net_ip.h>
+
+#define NETMASK0 255
+#define NETMASK1 255
+#define NETMASK2 255
+#define NETMASK3 0
+
+#define CLIENT_IPADDR0 192
+#define CLIENT_IPADDR1 168
+#define CLIENT_IPADDR2 1
+#define CLIENT_IPADDR3 100
+
+#define SERVER_IPADDR0 192
+#define SERVER_IPADDR1 168
+#define SERVER_IPADDR2 1
+#define SERVER_IPADDR3 10
+
+#define SERVER_PORT 5353
+#define CLIENT_PORT 0
+
+#define TCP_RX_TIMEOUT 50
+#define TCP_RETRY_TIMEOUT 50
+
+#define APP_SLEEP_TICKS 10
+#define APP_PROTOCOL IPPROTO_UDP
+
+#endif
diff --git a/samples/net/dns_client/testcase.ini b/samples/net/dns_client/testcase.ini
index 99297a617..24587c836 100644
--- a/samples/net/dns_client/testcase.ini
+++ b/samples/net/dns_client/testcase.ini
@@ -1,5 +1,4 @@
[test]
-tags = net
+tags = net dns
build_only = true
-arch_whitelist = x86
platform_whitelist = galileo