You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/05 23:02:21 UTC
[2/2] incubator-mynewt-larva git commit: Rename some host files with
the "ble_hs_" prefix.
Rename some host files with the "ble_hs_" prefix.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/4bb34e7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4bb34e7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4bb34e7f
Branch: refs/heads/master
Commit: 4bb34e7f210c649d6b584f50e738488abfea9d6c
Parents: f67286b
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Nov 5 14:01:18 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Nov 5 14:01:18 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/attr.h | 79 -------
net/nimble/host/include/host/ble_hs.h | 32 +++
net/nimble/host/include/host/ble_hs_test.h | 23 ++
net/nimble/host/include/host/host_task.h | 32 ---
net/nimble/host/include/host/host_test.h | 23 --
net/nimble/host/src/arch/sim/ble_hs_itf.c | 298 ++++++++++++++++++++++++
net/nimble/host/src/arch/sim/itf.c | 298 ------------------------
net/nimble/host/src/ble_hs.c | 123 ++++++++++
net/nimble/host/src/ble_hs_att.c | 1 -
net/nimble/host/src/ble_hs_att.h | 55 +++++
net/nimble/host/src/ble_hs_itf.h | 30 +++
net/nimble/host/src/host_hci.c | 2 +-
net/nimble/host/src/host_task.c | 123 ----------
net/nimble/host/src/itf.h | 30 ---
net/nimble/host/src/test/ble_hs_test.c | 77 ++++++
net/nimble/host/src/test/l2cap_test.c | 77 ------
project/host_test/src/main.c | 2 +-
17 files changed, 640 insertions(+), 665 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/include/host/attr.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/attr.h b/net/nimble/host/include/host/attr.h
deleted file mode 100644
index 2a37cbb..0000000
--- a/net/nimble/host/include/host/attr.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 _BLE_HOST_ATTR_H
-#define _BLE_HOST_ATTR_H
-
-#include <host/uuid.h>
-#include <os/os.h>
-#include <os/queue.h>
-
-#define BLE_HOST_EVENT_NEW_ATTR_CONN (OS_EVENT_T_PERUSER)
-
-struct ble_att_chan {
- int c_fd;
- int c_state;
-};
-
-struct host_attr;
-
-/**
- * Called from host_attr_walk(). Called on each entry in the
- * host_attr_list.
- *
- * @param Contains the current host_attr being iterated through
- * @param The user supplied argument to host_attr_walk()
- *
- * @return 0 on continue, 1 on stop
- */
-typedef int (*host_attr_walk_func_t)(struct host_attr *, void *arg);
-
-/**
- * Handles a host attribute request.
- *
- * @param The host attribute being requested
- * @param The request data associated with that host attribute
- */
-typedef int (*host_attr_handle_func_t)(struct host_attr *, uint8_t *data);
-
-#define HA_FLAG_PERM_READ (1 << 0)
-#define HA_FLAG_PERM_WRITE (1 << 1)
-#define HA_FLAG_PERM_RW (1 << 2)
-#define HA_FLAG_ENC_REQ (1 << 3)
-#define HA_FLAG_AUTHENTICATION_REQ (1 << 4)
-#define HA_FLAG_AUTHORIZATION_REQ (1 << 5)
-
-struct host_attr {
- ble_uuid_t ha_uuid;
- uint8_t ha_flags;
- uint8_t ha_pad1;
- uint16_t ha_handle_id;
- STAILQ_ENTRY(host_attr) ha_next;
-};
-
-
-#define HA_OPCODE_METHOD_START (0)
-#define HA_OPCODE_METHOD_END (5)
-#define HA_OPCODE_COMMAND_FLAG (1 << 6)
-#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7)
-
-
-#define HA_METH_ERROR_RSP (0x01)
-#define HA_METH_EXCHANGE_MTU_REQ (0x02)
-#define HA_METH_EXCHANGE_MTU_RSP (0x03)
-
-
-#endif /* _BLE_HOST_ATTR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
new file mode 100644
index 0000000..f9a3a94
--- /dev/null
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * 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 _BLE_HOST_H
+#define _BLE_HOST_H
+
+#include <inttypes.h>
+
+extern int ble_host_listen_enabled;
+
+/** --- */
+
+void ble_host_task_handler(void *arg);
+int ble_host_send_data_connectionless(uint16_t con_handle, uint16_t cid,
+ uint8_t *data, uint16_t len);
+int ble_host_poll(void);
+int host_init(void);
+
+#endif /* _BLE_HOST_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
new file mode 100644
index 0000000..92d020e
--- /dev/null
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * 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 H_HOST_TEST_
+#define H_HOST_TEST_
+
+int l2cap_test_all(void);
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/include/host/host_task.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_task.h b/net/nimble/host/include/host/host_task.h
deleted file mode 100644
index f9a3a94..0000000
--- a/net/nimble/host/include/host/host_task.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 _BLE_HOST_H
-#define _BLE_HOST_H
-
-#include <inttypes.h>
-
-extern int ble_host_listen_enabled;
-
-/** --- */
-
-void ble_host_task_handler(void *arg);
-int ble_host_send_data_connectionless(uint16_t con_handle, uint16_t cid,
- uint8_t *data, uint16_t len);
-int ble_host_poll(void);
-int host_init(void);
-
-#endif /* _BLE_HOST_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/include/host/host_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_test.h b/net/nimble/host/include/host/host_test.h
deleted file mode 100644
index 92d020e..0000000
--- a/net/nimble/host/include/host/host_test.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 H_HOST_TEST_
-#define H_HOST_TEST_
-
-int l2cap_test_all(void);
-
-#endif
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/arch/sim/ble_hs_itf.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/arch/sim/ble_hs_itf.c b/net/nimble/host/src/arch/sim/ble_hs_itf.c
new file mode 100644
index 0000000..d115c0e
--- /dev/null
+++ b/net/nimble/host/src/arch/sim/ble_hs_itf.c
@@ -0,0 +1,298 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * 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 <os/os.h>
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <unistd.h>
+#include "nimble/ble.h"
+#include "nimble/hci_common.h"
+#include "host/ble_hs.h"
+#include "host/host_hci.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_att.h"
+#include "ble_hs_itf.h"
+
+#define BLE_SIM_BASE_PORT 10000
+
+static void
+set_nonblock(int fd)
+{
+ int flags;
+ int rc;
+
+ flags = fcntl(fd, F_GETFL, 0);
+ rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+ assert(rc >= 0);
+}
+
+
+int
+ble_sim_listen(uint16_t con_handle)
+{
+ struct ble_hs_conn *conn;
+ struct sockaddr_in sin;
+ struct hostent *ent;
+ int fd;
+ int rc;
+
+ conn = ble_hs_conn_alloc();
+ if (conn == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+
+ /* resolve host addr first, then create a socket and bind() to
+ * that address.
+ */
+ ent = gethostbyname("localhost");
+ if (ent == NULL) {
+ rc = errno;
+ goto err;
+ }
+
+ memset(&sin, 0, sizeof(sin));
+ memcpy(&sin.sin_addr, ent->h_addr_list[0], ent->h_length);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(BLE_SIM_BASE_PORT + con_handle);
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ rc = errno;
+ goto err;
+ }
+
+ set_nonblock(fd);
+
+ rc = bind(fd, (struct sockaddr *)&sin, sizeof sin);
+ if (rc != 0) {
+ close(fd);
+ rc = errno;
+ goto err;
+ }
+
+ memset(conn, 0, sizeof *conn);
+ conn->bhc_handle = con_handle;
+ conn->bhc_fd = fd;
+
+ return 0;
+
+err:
+ ble_hs_conn_free(conn);
+ return rc;
+}
+
+static int
+ble_sim_connect(uint16_t con_handle, struct ble_hs_conn **out_conn)
+{
+ struct ble_hs_conn *conn;
+ struct sockaddr_in sin;
+ struct hostent *ent;
+ int fd;
+ int rc;
+
+ conn = ble_hs_conn_alloc();
+ if (conn == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+
+ /* resolve host addr first, then create a socket and bind() to
+ * that address.
+ */
+ ent = gethostbyname("localhost");
+ if (ent == NULL) {
+ rc = errno;
+ goto err;
+ }
+
+ memset(&sin, 0, sizeof(sin));
+ memcpy(&sin.sin_addr, ent->h_addr_list[0], ent->h_length);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(BLE_SIM_BASE_PORT + con_handle);
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ rc = errno;
+ goto err;
+ }
+
+ set_nonblock(fd);
+
+ rc = connect(fd, (struct sockaddr *)&sin, sizeof sin);
+ if (rc != 0 && errno != EINPROGRESS) {
+ rc = errno;
+ goto err;
+ }
+
+ memset(conn, 0, sizeof *conn);
+ conn->bhc_handle = con_handle;
+ conn->bhc_fd = fd;
+
+ *out_conn = conn;
+
+ return 0;
+
+err:
+ ble_hs_conn_free(conn);
+ *out_conn = NULL;
+ return rc;
+}
+
+static int
+ble_sim_ensure_connection(uint16_t con_handle, struct ble_hs_conn **conn)
+{
+ int rc;
+
+ *conn = ble_hs_conn_find(con_handle);
+ if (*conn == NULL) {
+ rc = ble_sim_connect(con_handle, conn);
+ if (rc != 0) {
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+static int
+ble_sim_send(uint16_t con_handle, const void *data, uint16_t len)
+{
+ struct ble_hs_conn *conn;
+ int rc;
+ int i;
+
+ rc = ble_sim_ensure_connection(con_handle, &conn);
+ if (rc != 0) {
+ return rc;
+ }
+
+ printf("sending %d bytes: ", len);
+ for (i = 0; i < len; i++) {
+ printf("%02x ", ((const uint8_t *)data)[i]);
+ }
+ printf("\n");
+
+ while (len > 0) {
+ rc = send(conn->bhc_fd, data, len, 0);
+ if (rc >= 0) {
+ data += rc;
+ len -= rc;
+ } else {
+ return errno;
+ }
+ }
+
+ return 0;
+}
+
+int
+ble_host_sim_send_data_connectionless(uint16_t con_handle, uint16_t cid,
+ uint8_t *data, uint16_t len)
+{
+ static uint8_t buf[1024];
+ int off;
+ int rc;
+
+ off = 0;
+
+ htole16(buf + off, con_handle | (0 << 12) | (0 << 14));
+ off += 2;
+
+ htole16(buf + off, len + 4);
+ off += 2;
+
+ htole16(buf + off, len);
+ off += 2;
+
+ htole16(buf + off, cid);
+ off += 2;
+
+ memcpy(buf + off, data, len);
+ off += len;
+
+ rc = ble_sim_send(con_handle, buf, off);
+ return rc;
+}
+
+int
+ble_host_sim_poll(void)
+{
+ static uint8_t buf[1024];
+ struct ble_hs_conn *conn;
+ fd_set r_fd_set;
+ fd_set w_fd_set;
+ uint16_t pkt_size;
+ int nevents;
+ int max_fd;
+ int fd;
+ int rc;
+ int i;
+
+ FD_ZERO(&r_fd_set);
+ FD_ZERO(&w_fd_set);
+
+ max_fd = 0;
+ for (conn = ble_hs_conn_first();
+ conn != NULL;
+ conn = SLIST_NEXT(conn, bhc_next)) {
+
+ fd = conn->bhc_fd;
+ FD_SET(fd, &r_fd_set);
+ FD_SET(fd, &w_fd_set);
+ if (fd > max_fd) {
+ max_fd = fd;
+ }
+ }
+
+ do {
+ nevents = select(max_fd + 1, &r_fd_set, &w_fd_set, NULL, NULL);
+ } while (nevents < 0 && errno == EINTR);
+
+ if (nevents > 0) {
+ for (conn = ble_hs_conn_first();
+ conn != NULL;
+ conn = SLIST_NEXT(conn, bhc_next)) {
+
+ if (FD_ISSET(conn->bhc_fd, &r_fd_set)) {
+ while (1) {
+ rc = recv(conn->bhc_fd, buf, sizeof buf, 0);
+ if (rc <= 0) {
+ break;
+ }
+ pkt_size = rc;
+
+ printf("received HCI data packet (%d bytes): ", pkt_size);
+ for (i = 0; i < pkt_size; i++) {
+ printf("%02x ", buf[i]);
+ }
+ printf("\n");
+
+ rc = host_hci_data_rx(buf, pkt_size);
+ }
+ }
+ }
+ }
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/arch/sim/itf.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/arch/sim/itf.c b/net/nimble/host/src/arch/sim/itf.c
deleted file mode 100644
index 0d4d110..0000000
--- a/net/nimble/host/src/arch/sim/itf.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 <os/os.h>
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <unistd.h>
-#include "nimble/ble.h"
-#include "nimble/hci_common.h"
-#include "host/attr.h"
-#include "host/host_task.h"
-#include "host/host_hci.h"
-#include "ble_hs_conn.h"
-#include "itf.h"
-
-#define BLE_SIM_BASE_PORT 10000
-
-static void
-set_nonblock(int fd)
-{
- int flags;
- int rc;
-
- flags = fcntl(fd, F_GETFL, 0);
- rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- assert(rc >= 0);
-}
-
-
-int
-ble_sim_listen(uint16_t con_handle)
-{
- struct ble_hs_conn *conn;
- struct sockaddr_in sin;
- struct hostent *ent;
- int fd;
- int rc;
-
- conn = ble_hs_conn_alloc();
- if (conn == NULL) {
- rc = ENOMEM;
- goto err;
- }
-
- /* resolve host addr first, then create a socket and bind() to
- * that address.
- */
- ent = gethostbyname("localhost");
- if (ent == NULL) {
- rc = errno;
- goto err;
- }
-
- memset(&sin, 0, sizeof(sin));
- memcpy(&sin.sin_addr, ent->h_addr_list[0], ent->h_length);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(BLE_SIM_BASE_PORT + con_handle);
-
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0) {
- rc = errno;
- goto err;
- }
-
- set_nonblock(fd);
-
- rc = bind(fd, (struct sockaddr *)&sin, sizeof sin);
- if (rc != 0) {
- close(fd);
- rc = errno;
- goto err;
- }
-
- memset(conn, 0, sizeof *conn);
- conn->bhc_handle = con_handle;
- conn->bhc_fd = fd;
-
- return 0;
-
-err:
- ble_hs_conn_free(conn);
- return rc;
-}
-
-static int
-ble_sim_connect(uint16_t con_handle, struct ble_hs_conn **out_conn)
-{
- struct ble_hs_conn *conn;
- struct sockaddr_in sin;
- struct hostent *ent;
- int fd;
- int rc;
-
- conn = ble_hs_conn_alloc();
- if (conn == NULL) {
- rc = ENOMEM;
- goto err;
- }
-
- /* resolve host addr first, then create a socket and bind() to
- * that address.
- */
- ent = gethostbyname("localhost");
- if (ent == NULL) {
- rc = errno;
- goto err;
- }
-
- memset(&sin, 0, sizeof(sin));
- memcpy(&sin.sin_addr, ent->h_addr_list[0], ent->h_length);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(BLE_SIM_BASE_PORT + con_handle);
-
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0) {
- rc = errno;
- goto err;
- }
-
- set_nonblock(fd);
-
- rc = connect(fd, (struct sockaddr *)&sin, sizeof sin);
- if (rc != 0 && errno != EINPROGRESS) {
- rc = errno;
- goto err;
- }
-
- memset(conn, 0, sizeof *conn);
- conn->bhc_handle = con_handle;
- conn->bhc_fd = fd;
-
- *out_conn = conn;
-
- return 0;
-
-err:
- ble_hs_conn_free(conn);
- *out_conn = NULL;
- return rc;
-}
-
-static int
-ble_sim_ensure_connection(uint16_t con_handle, struct ble_hs_conn **conn)
-{
- int rc;
-
- *conn = ble_hs_conn_find(con_handle);
- if (*conn == NULL) {
- rc = ble_sim_connect(con_handle, conn);
- if (rc != 0) {
- return rc;
- }
- }
-
- return 0;
-}
-
-static int
-ble_sim_send(uint16_t con_handle, const void *data, uint16_t len)
-{
- struct ble_hs_conn *conn;
- int rc;
- int i;
-
- rc = ble_sim_ensure_connection(con_handle, &conn);
- if (rc != 0) {
- return rc;
- }
-
- printf("sending %d bytes: ", len);
- for (i = 0; i < len; i++) {
- printf("%02x ", ((const uint8_t *)data)[i]);
- }
- printf("\n");
-
- while (len > 0) {
- rc = send(conn->bhc_fd, data, len, 0);
- if (rc >= 0) {
- data += rc;
- len -= rc;
- } else {
- return errno;
- }
- }
-
- return 0;
-}
-
-int
-ble_host_sim_send_data_connectionless(uint16_t con_handle, uint16_t cid,
- uint8_t *data, uint16_t len)
-{
- static uint8_t buf[1024];
- int off;
- int rc;
-
- off = 0;
-
- htole16(buf + off, con_handle | (0 << 12) | (0 << 14));
- off += 2;
-
- htole16(buf + off, len + 4);
- off += 2;
-
- htole16(buf + off, len);
- off += 2;
-
- htole16(buf + off, cid);
- off += 2;
-
- memcpy(buf + off, data, len);
- off += len;
-
- rc = ble_sim_send(con_handle, buf, off);
- return rc;
-}
-
-int
-ble_host_sim_poll(void)
-{
- static uint8_t buf[1024];
- struct ble_hs_conn *conn;
- fd_set r_fd_set;
- fd_set w_fd_set;
- uint16_t pkt_size;
- int nevents;
- int max_fd;
- int fd;
- int rc;
- int i;
-
- FD_ZERO(&r_fd_set);
- FD_ZERO(&w_fd_set);
-
- max_fd = 0;
- for (conn = ble_hs_conn_first();
- conn != NULL;
- conn = SLIST_NEXT(conn, bhc_next)) {
-
- fd = conn->bhc_fd;
- FD_SET(fd, &r_fd_set);
- FD_SET(fd, &w_fd_set);
- if (fd > max_fd) {
- max_fd = fd;
- }
- }
-
- do {
- nevents = select(max_fd + 1, &r_fd_set, &w_fd_set, NULL, NULL);
- } while (nevents < 0 && errno == EINTR);
-
- if (nevents > 0) {
- for (conn = ble_hs_conn_first();
- conn != NULL;
- conn = SLIST_NEXT(conn, bhc_next)) {
-
- if (FD_ISSET(conn->bhc_fd, &r_fd_set)) {
- while (1) {
- rc = recv(conn->bhc_fd, buf, sizeof buf, 0);
- if (rc <= 0) {
- break;
- }
- pkt_size = rc;
-
- printf("received HCI data packet (%d bytes): ", pkt_size);
- for (i = 0; i < pkt_size; i++) {
- printf("%02x ", buf[i]);
- }
- printf("\n");
-
- rc = host_hci_data_rx(buf, pkt_size);
- }
- }
- }
- }
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
new file mode 100644
index 0000000..e81c42e
--- /dev/null
+++ b/net/nimble/host/src/ble_hs.c
@@ -0,0 +1,123 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * 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 <assert.h>
+#include "os/os.h"
+#include "host/ble_hs.h"
+#include "ble_hs_att.h"
+#include "ble_hs_conn.h"
+#ifdef ARCH_sim
+#include "ble_hs_itf.h"
+#endif
+
+
+int ble_host_listen_enabled;
+
+static struct os_eventq host_task_evq;
+//static struct ble_att_chan default_attr_chan;
+static struct os_callout ble_host_task_timer;
+
+int
+ble_host_send_data_connectionless(uint16_t con_handle, uint16_t cid,
+ uint8_t *data, uint16_t len)
+{
+ int rc;
+
+#ifdef ARCH_sim
+ rc = ble_host_sim_send_data_connectionless(con_handle, cid, data, len);
+#else
+ rc = -1;
+#endif
+
+ return rc;
+}
+
+/**
+ * XXX: This is only here for testing.
+ */
+int
+ble_host_poll(void)
+{
+ int rc;
+
+#ifdef ARCH_sim
+ rc = ble_host_sim_poll();
+#else
+ rc = -1;
+#endif
+
+ return rc;
+}
+
+void
+ble_host_task_handler(void *arg)
+{
+ struct os_event *ev;
+
+ os_callout_reset(&ble_host_task_timer, 50);
+
+ /**
+ * How do we decide what channels to listen on for data? This must be
+ * configured to the host task. Maintain a list of channels to
+ *
+ */
+ while (1) {
+ ev = os_eventq_get(&host_task_evq);
+ switch (ev->ev_type) {
+ case OS_EVENT_T_TIMER:
+ /* Poll the attribute channel */
+ //ble_att_chan_poll(&default_attr_chan, &host_task_evq);
+ /* Reset callout, wakeup every 50ms */
+ os_callout_reset(&ble_host_task_timer, 50);
+ break;
+ case BLE_HOST_EVENT_NEW_ATTR_CONN:
+ break;
+ }
+ }
+}
+
+/**
+ * Initialize the host portion of the BLE stack.
+ */
+int
+host_init(void)
+{
+ int rc;
+
+ os_eventq_init(&host_task_evq);
+ os_callout_init(&ble_host_task_timer, &host_task_evq, NULL);
+
+ rc = ble_hs_conn_init();
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_l2cap_init();
+ if (rc != 0) {
+ return rc;
+ }
+
+#ifdef ARCH_sim
+ if (ble_host_listen_enabled) {
+ int rc;
+
+ rc = ble_sim_listen(1);
+ assert(rc == 0);
+ }
+#endif
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/ble_hs_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.c b/net/nimble/host/src/ble_hs_att.c
index 0d28723..c2e0fc8 100644
--- a/net/nimble/host/src/ble_hs_att.c
+++ b/net/nimble/host/src/ble_hs_att.c
@@ -19,7 +19,6 @@
#include <assert.h>
#include "os/os.h"
#include "nimble/ble.h"
-#include "host/attr.h"
#include "ble_l2cap.h"
#include "ble_l2cap_util.h"
#include "ble_hs_conn.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/ble_hs_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.h b/net/nimble/host/src/ble_hs_att.h
index 9ad7d9b..feb8c2b 100644
--- a/net/nimble/host/src/ble_hs_att.h
+++ b/net/nimble/host/src/ble_hs_att.h
@@ -17,6 +17,61 @@
#ifndef H_BLE_HS_ATT_
#define H_BLE_HS_ATT_
+#include "host/uuid.h"
+
+#define BLE_HOST_EVENT_NEW_ATTR_CONN (OS_EVENT_T_PERUSER)
+
+struct ble_att_chan {
+ int c_fd;
+ int c_state;
+};
+
+struct host_attr;
+
+/**
+ * Called from host_attr_walk(). Called on each entry in the
+ * host_attr_list.
+ *
+ * @param Contains the current host_attr being iterated through
+ * @param The user supplied argument to host_attr_walk()
+ *
+ * @return 0 on continue, 1 on stop
+ */
+typedef int (*host_attr_walk_func_t)(struct host_attr *, void *arg);
+
+/**
+ * Handles a host attribute request.
+ *
+ * @param The host attribute being requested
+ * @param The request data associated with that host attribute
+ */
+typedef int (*host_attr_handle_func_t)(struct host_attr *, uint8_t *data);
+
+#define HA_FLAG_PERM_READ (1 << 0)
+#define HA_FLAG_PERM_WRITE (1 << 1)
+#define HA_FLAG_PERM_RW (1 << 2)
+#define HA_FLAG_ENC_REQ (1 << 3)
+#define HA_FLAG_AUTHENTICATION_REQ (1 << 4)
+#define HA_FLAG_AUTHORIZATION_REQ (1 << 5)
+
+struct host_attr {
+ ble_uuid_t ha_uuid;
+ uint8_t ha_flags;
+ uint8_t ha_pad1;
+ uint16_t ha_handle_id;
+ STAILQ_ENTRY(host_attr) ha_next;
+};
+
+#define HA_OPCODE_METHOD_START (0)
+#define HA_OPCODE_METHOD_END (5)
+#define HA_OPCODE_COMMAND_FLAG (1 << 6)
+#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7)
+
+
+#define HA_METH_ERROR_RSP (0x01)
+#define HA_METH_EXCHANGE_MTU_REQ (0x02)
+#define HA_METH_EXCHANGE_MTU_RSP (0x03)
+
struct ble_l2cap_chan *ble_hs_att_create_chan(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/ble_hs_itf.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_itf.h b/net/nimble/host/src/ble_hs_itf.h
new file mode 100644
index 0000000..12d2887
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_itf.h
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * 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 H_ITF_
+#define H_ITF_
+
+struct ble_att_chan;
+struct os_eventq;
+
+int ble_att_chan_open_default(struct ble_att_chan *ac);
+int ble_att_chan_poll(struct ble_att_chan *c, struct os_eventq *evq);
+int ble_host_sim_send_data_connectionless(uint16_t con_handle, uint16_t cid,
+ uint8_t *data, uint16_t len);
+int ble_sim_listen(uint16_t con_handle);
+int ble_host_sim_poll(void);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index a52ffbd..5a91336 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -22,7 +22,7 @@
#include "console/console.h"
#include "nimble/hci_common.h"
#include "nimble/hci_transport.h"
-#include "host/host_task.h"
+#include "host/ble_hs.h"
#include "host_dbg.h"
#include "ble_hs_conn.h"
#include "ble_l2cap.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/host_task.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_task.c b/net/nimble/host/src/host_task.c
deleted file mode 100644
index 196d011..0000000
--- a/net/nimble/host/src/host_task.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 <assert.h>
-#include "os/os.h"
-#include "host/attr.h"
-#include "host/host_task.h"
-#include "ble_hs_conn.h"
-#ifdef ARCH_sim
-#include "itf.h"
-#endif
-
-
-int ble_host_listen_enabled;
-
-static struct os_eventq host_task_evq;
-//static struct ble_att_chan default_attr_chan;
-static struct os_callout ble_host_task_timer;
-
-int
-ble_host_send_data_connectionless(uint16_t con_handle, uint16_t cid,
- uint8_t *data, uint16_t len)
-{
- int rc;
-
-#ifdef ARCH_sim
- rc = ble_host_sim_send_data_connectionless(con_handle, cid, data, len);
-#else
- rc = -1;
-#endif
-
- return rc;
-}
-
-/**
- * XXX: This is only here for testing.
- */
-int
-ble_host_poll(void)
-{
- int rc;
-
-#ifdef ARCH_sim
- rc = ble_host_sim_poll();
-#else
- rc = -1;
-#endif
-
- return rc;
-}
-
-void
-ble_host_task_handler(void *arg)
-{
- struct os_event *ev;
-
- os_callout_reset(&ble_host_task_timer, 50);
-
- /**
- * How do we decide what channels to listen on for data? This must be
- * configured to the host task. Maintain a list of channels to
- *
- */
- while (1) {
- ev = os_eventq_get(&host_task_evq);
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- /* Poll the attribute channel */
- //ble_att_chan_poll(&default_attr_chan, &host_task_evq);
- /* Reset callout, wakeup every 50ms */
- os_callout_reset(&ble_host_task_timer, 50);
- break;
- case BLE_HOST_EVENT_NEW_ATTR_CONN:
- break;
- }
- }
-}
-
-/**
- * Initialize the host portion of the BLE stack.
- */
-int
-host_init(void)
-{
- int rc;
-
- os_eventq_init(&host_task_evq);
- os_callout_init(&ble_host_task_timer, &host_task_evq, NULL);
-
- rc = ble_hs_conn_init();
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_l2cap_init();
- if (rc != 0) {
- return rc;
- }
-
-#ifdef ARCH_sim
- if (ble_host_listen_enabled) {
- int rc;
-
- rc = ble_sim_listen(1);
- assert(rc == 0);
- }
-#endif
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/itf.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/itf.h b/net/nimble/host/src/itf.h
deleted file mode 100644
index 12d2887..0000000
--- a/net/nimble/host/src/itf.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * 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 H_ITF_
-#define H_ITF_
-
-struct ble_att_chan;
-struct os_eventq;
-
-int ble_att_chan_open_default(struct ble_att_chan *ac);
-int ble_att_chan_poll(struct ble_att_chan *c, struct os_eventq *evq);
-int ble_host_sim_send_data_connectionless(uint16_t con_handle, uint16_t cid,
- uint8_t *data, uint16_t len);
-int ble_sim_listen(uint16_t con_handle);
-int ble_host_sim_poll(void);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
new file mode 100644
index 0000000..79b621f
--- /dev/null
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -0,0 +1,77 @@
+#include <stddef.h>
+#include <errno.h>
+#include "nimble/hci_common.h"
+#include "host/ble_hs.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_conn.h"
+#include "ble_l2cap.h"
+#include "testutil/testutil.h"
+
+TEST_CASE(l2cap_test_bad_header)
+{
+ struct ble_l2cap_hdr l2cap_hdr;
+ struct hci_data_hdr hci_hdr;
+ struct ble_hs_conn *conn;
+ uint8_t pkt[8];
+ int rc;
+
+ conn = ble_hs_conn_alloc();
+ TEST_ASSERT_FATAL(conn != NULL);
+
+ hci_hdr.hdh_handle_pb_bc = 0;
+ hci_hdr.hdh_len = 10;
+
+ /* HCI header indicates a length of 10, but L2CAP header has a length
+ * of 0.
+ */
+ l2cap_hdr.blh_len = 0;
+ l2cap_hdr.blh_cid = 0;
+ rc = ble_l2cap_write_hdr(pkt, sizeof pkt, &l2cap_hdr);
+ TEST_ASSERT(rc == 0);
+ rc = ble_l2cap_rx(conn, &hci_hdr, pkt);
+ TEST_ASSERT(rc == EMSGSIZE);
+
+ /* Length is correct; specified channel doesn't exist. */
+ l2cap_hdr.blh_len = 6;
+ l2cap_hdr.blh_cid = 0;
+ rc = ble_l2cap_write_hdr(pkt, sizeof pkt, &l2cap_hdr);
+ TEST_ASSERT(rc == 0);
+ rc = ble_l2cap_rx(conn, &hci_hdr, pkt);
+ TEST_ASSERT(rc == ENOENT);
+
+ ble_hs_conn_free(conn);
+}
+
+TEST_SUITE(l2cap_gen)
+{
+ int rc;
+
+ rc = host_init();
+ TEST_ASSERT_FATAL(rc == 0);
+
+ l2cap_test_bad_header();
+}
+
+int
+l2cap_test_all(void)
+{
+ l2cap_gen();
+
+ return tu_any_failed;
+}
+
+#ifdef PKG_TEST
+
+int
+main(void)
+{
+ tu_config.tc_print_results = 1;
+ tu_init();
+
+ l2cap_test_all();
+
+ return tu_any_failed;
+}
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/net/nimble/host/src/test/l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/l2cap_test.c b/net/nimble/host/src/test/l2cap_test.c
deleted file mode 100644
index 0b96ca0..0000000
--- a/net/nimble/host/src/test/l2cap_test.c
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stddef.h>
-#include <errno.h>
-#include "nimble/hci_common.h"
-#include "ble_hs_conn.h"
-#include "ble_l2cap.h"
-#include "host/host_task.h"
-#include "host/host_test.h"
-#include "testutil/testutil.h"
-
-TEST_CASE(l2cap_test_bad_header)
-{
- struct ble_l2cap_hdr l2cap_hdr;
- struct hci_data_hdr hci_hdr;
- struct ble_hs_conn *conn;
- uint8_t pkt[8];
- int rc;
-
- conn = ble_hs_conn_alloc();
- TEST_ASSERT_FATAL(conn != NULL);
-
- hci_hdr.hdh_handle_pb_bc = 0;
- hci_hdr.hdh_len = 10;
-
- /* HCI header indicates a length of 10, but L2CAP header has a length
- * of 0.
- */
- l2cap_hdr.blh_len = 0;
- l2cap_hdr.blh_cid = 0;
- rc = ble_l2cap_write_hdr(pkt, sizeof pkt, &l2cap_hdr);
- TEST_ASSERT(rc == 0);
- rc = ble_l2cap_rx(conn, &hci_hdr, pkt);
- TEST_ASSERT(rc == EMSGSIZE);
-
- /* Length is correct; specified channel doesn't exist. */
- l2cap_hdr.blh_len = 6;
- l2cap_hdr.blh_cid = 0;
- rc = ble_l2cap_write_hdr(pkt, sizeof pkt, &l2cap_hdr);
- TEST_ASSERT(rc == 0);
- rc = ble_l2cap_rx(conn, &hci_hdr, pkt);
- TEST_ASSERT(rc == ENOENT);
-
- ble_hs_conn_free(conn);
-}
-
-TEST_SUITE(l2cap_gen)
-{
- int rc;
-
- rc = host_init();
- TEST_ASSERT_FATAL(rc == 0);
-
- l2cap_test_bad_header();
-}
-
-int
-l2cap_test_all(void)
-{
- l2cap_gen();
-
- return tu_any_failed;
-}
-
-#ifdef PKG_TEST
-
-int
-main(void)
-{
- tu_config.tc_print_results = 1;
- tu_init();
-
- l2cap_test_all();
-
- return tu_any_failed;
-}
-
-#endif
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bb34e7f/project/host_test/src/main.c
----------------------------------------------------------------------
diff --git a/project/host_test/src/main.c b/project/host_test/src/main.c
index c981581..846a3f7 100755
--- a/project/host_test/src/main.c
+++ b/project/host_test/src/main.c
@@ -19,7 +19,7 @@
#include "os/os.h"
#include "nimble/ble.h"
#include "host/host_hci.h"
-#include "host/host_task.h"
+#include "host/ble_hs.h"
#define HOST_TASK_PRIO (1)
#define HOST_STACK_SIZE (OS_STACK_ALIGN(4096))