summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2016-09-30 14:03:14 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2016-10-16 09:01:28 +0300
commite6cb507a42aa53323ea06f6aa8c2c72bc42171a8 (patch)
tree37ed6085f7fa40b6963a006110844837b501779c /samples
parentd6acfcf6a0f162de514cdc874502e501559257ac (diff)
Bluetooth: IPSS: Remove ipss_listen
This removes ipss_listen since it does depend on the old network stack it cause build problems with yaip and anyway its code is only used by ipsp sample while the net samples does not use ipss_listen at all. Change-Id: I23987670548741bde8800115d473a3bab242153b Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/bluetooth/gatt/ipss.c121
-rw-r--r--samples/bluetooth/gatt/ipss.h1
-rw-r--r--samples/bluetooth/ipsp/src/main.c121
3 files changed, 120 insertions, 123 deletions
diff --git a/samples/bluetooth/gatt/ipss.c b/samples/bluetooth/gatt/ipss.c
index a3f0d9954..f704520f3 100644
--- a/samples/bluetooth/gatt/ipss.c
+++ b/samples/bluetooth/gatt/ipss.c
@@ -32,24 +32,10 @@
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
-#include <net/ip_buf.h>
-#include <net/net_core.h>
-#include <net/net_socket.h>
-
#define DEVICE_NAME "Test IPSP node"
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define UNKNOWN_APPEARANCE 0x0000
-/* The 2001:db8::/32 is the private address space for documentation RFC 3849 */
-#define MY_IPADDR { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0, 0x2 } } }
-
-/* admin-local, dynamically allocated multicast address */
-#define MCAST_IPADDR { { { 0xff, 0x84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0x2 } } }
-
-#define UDP_PORT 4242
-
#if !defined(CONFIG_BLUETOOTH_GATT_DYNAMIC_DB)
static ssize_t read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
@@ -140,98 +126,6 @@ static struct bt_conn_cb conn_callbacks = {
.disconnected = disconnected,
};
-static inline void reverse(unsigned char *buf, int len)
-{
- int i, last = len - 1;
-
- for (i = 0; i < len / 2; i++) {
- unsigned char tmp = buf[i];
-
- buf[i] = buf[last - i];
- buf[last - i] = tmp;
- }
-}
-
-static inline struct net_buf *prepare_reply(const char *type,
- struct net_buf *buf)
-{
- printk("%s: received %d bytes\n", type, ip_buf_appdatalen(buf));
-
- /* In this test we reverse the received bytes.
- * We could just pass the data back as is but
- * this way it is possible to see how the app
- * can manipulate the received data.
- */
- reverse(ip_buf_appdata(buf), ip_buf_appdatalen(buf));
-
- return buf;
-}
-
-static inline bool get_context(struct net_context **recv,
- struct net_context **mcast_recv)
-{
- static struct net_addr mcast_addr;
- static struct net_addr any_addr;
- static struct net_addr my_addr;
- static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
- static const struct in6_addr in6addr_mcast = MCAST_IPADDR;
- static struct in6_addr in6addr_my = MY_IPADDR;
-
- mcast_addr.in6_addr = in6addr_mcast;
- mcast_addr.family = AF_INET6;
-
- any_addr.in6_addr = in6addr_any;
- any_addr.family = AF_INET6;
-
- my_addr.in6_addr = in6addr_my;
- my_addr.family = AF_INET6;
-
- *recv = net_context_get(IPPROTO_UDP,
- &any_addr, 0,
- &my_addr, UDP_PORT);
- if (!*recv) {
- printk("%s: Cannot get network context\n", __func__);
- return NULL;
- }
-
- *mcast_recv = net_context_get(IPPROTO_UDP,
- &any_addr, 0,
- &mcast_addr, UDP_PORT);
- if (!*mcast_recv) {
- printk("%s: Cannot get receiving mcast network context\n",
- __func__);
- return false;
- }
-
- return true;
-}
-
-static inline void receive_and_reply(struct net_context *recv,
- struct net_context *mcast_recv)
-{
- struct net_buf *buf;
-
- buf = net_receive(recv, TICKS_UNLIMITED);
- if (buf) {
- prepare_reply("unicast ", buf);
-
- if (net_reply(recv, buf)) {
- ip_buf_unref(buf);
- }
- return;
- }
-
- buf = net_receive(mcast_recv, TICKS_UNLIMITED);
- if (buf) {
- prepare_reply("multicast ", buf);
-
- if (net_reply(mcast_recv, buf)) {
- ip_buf_unref(buf);
- }
- return;
- }
-}
-
void ipss_init(void)
{
bt_gatt_register(attrs, ARRAY_SIZE(attrs));
@@ -251,18 +145,3 @@ int ipss_advertise(void)
return 0;
}
-
-void ipss_listen(void)
-{
- static struct net_context *recv;
- static struct net_context *mcast_recv;
-
- if (!get_context(&recv, &mcast_recv)) {
- printk("%s: Cannot get network contexts\n", __func__);
- return;
- }
-
- while (1) {
- receive_and_reply(recv, mcast_recv);
- }
-}
diff --git a/samples/bluetooth/gatt/ipss.h b/samples/bluetooth/gatt/ipss.h
index ca4c6b828..2a5bd0c82 100644
--- a/samples/bluetooth/gatt/ipss.h
+++ b/samples/bluetooth/gatt/ipss.h
@@ -20,4 +20,3 @@
void ipss_init(void);
int ipss_advertise(void);
-int ipss_listen(void);
diff --git a/samples/bluetooth/ipsp/src/main.c b/samples/bluetooth/ipsp/src/main.c
index f15cf040f..8a1786044 100644
--- a/samples/bluetooth/ipsp/src/main.c
+++ b/samples/bluetooth/ipsp/src/main.c
@@ -19,10 +19,129 @@
#include <zephyr.h>
#include <bluetooth/bluetooth.h>
+#include <net/ip_buf.h>
#include <net/net_core.h>
+#include <net/net_socket.h>
#include <gatt/ipss.h>
+#define UDP_PORT 4242
+
+/* The 2001:db8::/32 is the private address space for documentation RFC 3849 */
+#define MY_IPADDR { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0, 0x2 } } }
+
+/* admin-local, dynamically allocated multicast address */
+#define MCAST_IPADDR { { { 0xff, 0x84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0x2 } } }
+
+static inline void reverse(unsigned char *buf, int len)
+{
+ int i, last = len - 1;
+
+ for (i = 0; i < len / 2; i++) {
+ unsigned char tmp = buf[i];
+
+ buf[i] = buf[last - i];
+ buf[last - i] = tmp;
+ }
+}
+
+static inline struct net_buf *prepare_reply(const char *type,
+ struct net_buf *buf)
+{
+ printk("%s: received %d bytes\n", type, ip_buf_appdatalen(buf));
+
+ /* In this test we reverse the received bytes.
+ * We could just pass the data back as is but
+ * this way it is possible to see how the app
+ * can manipulate the received data.
+ */
+ reverse(ip_buf_appdata(buf), ip_buf_appdatalen(buf));
+
+ return buf;
+}
+
+static inline bool get_context(struct net_context **recv,
+ struct net_context **mcast_recv)
+{
+ static struct net_addr mcast_addr;
+ static struct net_addr any_addr;
+ static struct net_addr my_addr;
+ static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+ static const struct in6_addr in6addr_mcast = MCAST_IPADDR;
+ static struct in6_addr in6addr_my = MY_IPADDR;
+
+ mcast_addr.in6_addr = in6addr_mcast;
+ mcast_addr.family = AF_INET6;
+
+ any_addr.in6_addr = in6addr_any;
+ any_addr.family = AF_INET6;
+
+ my_addr.in6_addr = in6addr_my;
+ my_addr.family = AF_INET6;
+
+ *recv = net_context_get(IPPROTO_UDP,
+ &any_addr, 0,
+ &my_addr, UDP_PORT);
+ if (!*recv) {
+ printk("%s: Cannot get network context\n", __func__);
+ return NULL;
+ }
+
+ *mcast_recv = net_context_get(IPPROTO_UDP,
+ &any_addr, 0,
+ &mcast_addr, UDP_PORT);
+ if (!*mcast_recv) {
+ printk("%s: Cannot get receiving mcast network context\n",
+ __func__);
+ return false;
+ }
+
+ return true;
+}
+
+static inline void receive_and_reply(struct net_context *recv,
+ struct net_context *mcast_recv)
+{
+ struct net_buf *buf;
+
+ buf = net_receive(recv, TICKS_UNLIMITED);
+ if (buf) {
+ prepare_reply("unicast ", buf);
+
+ if (net_reply(recv, buf)) {
+ ip_buf_unref(buf);
+ }
+ return;
+ }
+
+ buf = net_receive(mcast_recv, TICKS_UNLIMITED);
+ if (buf) {
+ prepare_reply("multicast ", buf);
+
+ if (net_reply(mcast_recv, buf)) {
+ ip_buf_unref(buf);
+ }
+ return;
+ }
+}
+
+static void listen(void)
+{
+ static struct net_context *recv;
+ static struct net_context *mcast_recv;
+
+ if (!get_context(&recv, &mcast_recv)) {
+ printk("%s: Cannot get network contexts\n", __func__);
+ return;
+ }
+
+ while (1) {
+ receive_and_reply(recv, mcast_recv);
+ }
+}
+
void main(void)
{
int err;
@@ -47,5 +166,5 @@ void main(void)
printk("Advertising successfully started\n");
- ipss_listen();
+ listen();
}