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 2016/07/13 18:07:47 UTC

[1/4] incubator-mynewt-core git commit: os - Move callout list init from data to text

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/ble_hs_api 8da07efd3 -> c7c7c9c18


os - Move callout list init from data to text

This ensures the callout list gets initialized every time the OS is
initialized.  There were issues with stale callouts when unit tests
restarted the OS.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a5ab3ed2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a5ab3ed2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a5ab3ed2

Branch: refs/heads/ble_hs_api
Commit: a5ab3ed25751ae6b1e3720f361fe694204d01546
Parents: 2fbc2b6
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 11 20:22:53 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jul 12 16:48:06 2016 -0700

----------------------------------------------------------------------
 libs/os/src/os.c         | 3 +++
 libs/os/src/os_callout.c | 4 ++--
 libs/os/src/os_priv.h    | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5ab3ed2/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 5ec71ec..cbca765 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -19,6 +19,7 @@
 
 #include "os/os.h"
 #include "os/queue.h"
+#include "os_priv.h"
 
 #include "hal/hal_os_tick.h"
 
@@ -105,6 +106,8 @@ os_init(void)
 {
     os_error_t err;
 
+    TAILQ_INIT(&g_callout_list);
+
     err = os_arch_os_init();
     assert(err == OS_OK);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5ab3ed2/libs/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_callout.c b/libs/os/src/os_callout.c
index 02462c0..bc36a19 100644
--- a/libs/os/src/os_callout.c
+++ b/libs/os/src/os_callout.c
@@ -18,12 +18,12 @@
  */
 
 #include "os/os.h"
+#include "os_priv.h"
 
 #include <assert.h>
 #include <string.h>
 
-TAILQ_HEAD(, os_callout) g_callout_list =
-  TAILQ_HEAD_INITIALIZER(g_callout_list);
+struct os_callout_list g_callout_list;
 
 static void
 _os_callout_init(struct os_callout *c, struct os_eventq *evq, void *ev_arg)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5ab3ed2/libs/os/src/os_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/os_priv.h b/libs/os/src/os_priv.h
index dfc9e38..9566546 100644
--- a/libs/os/src/os_priv.h
+++ b/libs/os/src/os_priv.h
@@ -21,10 +21,12 @@
 #define H_OS_PRIV_
 
 TAILQ_HEAD(os_task_list, os_task);
+TAILQ_HEAD(os_callout_list, os_callout);
 
 extern struct os_task_list g_os_run_list;
 extern struct os_task_list g_os_sleep_list;
 extern struct os_task_list g_os_task_list;
 extern struct os_task *g_current_task;
+extern struct os_callout_list g_callout_list;
 
 #endif


[2/4] incubator-mynewt-core git commit: MYNEWT-314; First take on the socket interface.

Posted by cc...@apache.org.
MYNEWT-314; First take on the socket interface.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2fbc2b69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2fbc2b69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2fbc2b69

Branch: refs/heads/ble_hs_api
Commit: 2fbc2b699b92d2143cb6b152c57a93bb5bb26983
Parents: 8da07ef
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Jul 11 16:59:46 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jul 12 16:48:06 2016 -0700

----------------------------------------------------------------------
 sys/mn_socket/include/mn_socket/mn_socket.h     | 141 +++++++++++++++++++
 sys/mn_socket/include/mn_socket/mn_socket_ops.h |  82 +++++++++++
 sys/mn_socket/pkg.yml                           |  31 ++++
 sys/mn_socket/src/mn_socket.c                   | 123 ++++++++++++++++
 sys/mn_socket/src/mn_socket_aconv.c             |  57 ++++++++
 sys/mn_socket/src/test/mn_sock_test.c           |  82 +++++++++++
 6 files changed, 516 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/include/mn_socket/mn_socket.h
----------------------------------------------------------------------
diff --git a/sys/mn_socket/include/mn_socket/mn_socket.h b/sys/mn_socket/include/mn_socket/mn_socket.h
new file mode 100644
index 0000000..75ebc8c
--- /dev/null
+++ b/sys/mn_socket/include/mn_socket/mn_socket.h
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 __SYS_MN_SOCKET_H_
+#define __SYS_MN_SOCKET_H_
+
+#include <inttypes.h>
+
+/*
+ * Address/protocol family.
+ */
+#define MN_AF_INET              4
+#define MN_PF_INET              MN_AF_INET
+#define MN_AF_INET6             6
+#define MN_PF_INET6             MN_AF_INET6
+
+/*
+ * Socket types
+ */
+#define MN_SOCK_STREAM          1
+#define MN_SOCK_DGRAM           2
+
+/*
+ * Error codes from mn_socket interface.
+ */
+#define MN_EAFNOSUPPORT         1
+#define MN_EPROTONOSUPPORT      2
+#define MN_ENOBUFS              3
+#define MN_EINVAL               4
+#define MN_ENOTCONN             5
+#define MN_ECONNABORTED         6
+#define MN_EDESTADDRREQ         7
+#define MN_EADDRINUSE           8
+#define MN_ETIMEDOUT            9
+#define MN_EAGAIN               10
+#define MN_EUNKNOWN             11
+
+struct mn_socket;
+struct mn_socket_ops;
+struct mn_sock_cb;
+struct os_mbuf;
+
+struct mn_socket {
+    const union mn_socket_cb *ms_cbs;          /* filled in by user */
+    const struct mn_socket_ops *ms_ops;        /* filled in by mn_socket */
+};
+
+/*
+ * Callbacks. Socket callbacks are for sockets which exchange
+ * data. Listen callback is for TCP listen sockets.
+ */
+union mn_socket_cb {
+    struct {
+        void (*readable)(struct mn_socket *, int err);
+        void (*writable)(struct mn_socket *, int err);
+    } socket;
+    struct {
+        int (*newconn)(struct mn_socket *listen, struct mn_socket *new);
+    } listen;
+};
+
+struct mn_sockaddr {
+    uint8_t msa_len;
+    uint8_t msa_family;
+    char    msa_data[2];
+};
+
+struct mn_sockaddr_in {
+    uint8_t msin_len;
+    uint8_t msin_family;
+    uint16_t msin_port;
+    uint32_t msin_addr;
+};
+
+struct mn_sockaddr_in6 {
+    uint8_t msin6_len;
+    uint8_t msin6_family;
+    uint16_t msin6_port;
+    uint32_t msin6_flowinfo;
+    uint32_t msin6_addr[4];
+};
+
+/*
+ * Socket calls.
+ *
+ * mn_connect() for TCP is asynchronous. Once connection has been established,
+ * socket callback (*writable) will be called.
+ *
+ * mn_sendto() is asynchronous as well. If it fails due to buffer shortage,
+ * socket provider should call (*writable) when more data can be sent.
+ *
+ * mn_recvfrom() returns immediatelly if no data is available. If data arrives,
+ * the callback (*readable) will be called. Once that happens, owner of the
+ * socket should keep calling mn_recvfrom() until it has drained all the
+ * data from the socket.
+ *
+ * If remote end closes the socket, socket callback (*readable) will be
+ * called.
+ */
+int mn_socket(struct mn_socket **, uint8_t domain, uint8_t type, uint8_t proto);
+int mn_bind(struct mn_socket *, struct mn_sockaddr *);
+int mn_connect(struct mn_socket *, struct mn_sockaddr *);
+int mn_listen(struct mn_socket *, uint8_t qlen);
+
+int mn_recvfrom(struct mn_socket *, struct os_mbuf **,
+  struct mn_sockaddr *from);
+int mn_sendto(struct mn_socket *, struct os_mbuf *, struct mn_sockaddr *to);
+
+int mn_getsockopt(struct mn_socket *, uint8_t level, uint8_t optname,
+  void *optval);
+int mn_setsockopt(struct mn_socket *, uint8_t level, uint8_t optname,
+  void *optval);
+
+int mn_getsockname(struct mn_socket *, struct mn_sockaddr *);
+int mn_getpeername(struct mn_socket *, struct mn_sockaddr *);
+
+int mn_close(struct mn_socket *);
+
+#define mn_socket_set_cbs(sock, cbs) (sock)->ms_cbs = (cbs)
+
+/*
+ * Address conversion
+ */
+int mn_inet_pton(int af, const char *src, void *dst);
+
+#endif /* __SYS_MN_SOCKET_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/include/mn_socket/mn_socket_ops.h
----------------------------------------------------------------------
diff --git a/sys/mn_socket/include/mn_socket/mn_socket_ops.h b/sys/mn_socket/include/mn_socket/mn_socket_ops.h
new file mode 100644
index 0000000..6e768eb
--- /dev/null
+++ b/sys/mn_socket/include/mn_socket/mn_socket_ops.h
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 __SYS_MN_SOCKET_OPS_H_
+#define __SYS_MN_SOCKET_OPS_H_
+
+#include <inttypes.h>
+
+/*
+ * Interface for socket providers.
+ * - mso_create() creates a socket, memory allocation has to be done by
+ *   the socket provider.
+ * - mso_close() closes the socket, memory should be freed. User should not
+ *   be using the socket pointer once it has been closed.
+ */
+struct mn_socket_ops {
+    int (*mso_create)(struct mn_socket **, uint8_t domain, uint8_t type,
+      uint8_t protocol);
+    int (*mso_close)(struct mn_socket *);
+
+    int (*mso_bind)(struct mn_socket *, struct mn_sockaddr *);
+    int (*mso_connect)(struct mn_socket *, struct mn_sockaddr *);
+    int (*mso_listen)(struct mn_socket *, uint8_t qlen);
+
+    int (*mso_sendto)(struct mn_socket *, struct os_mbuf *,
+      struct mn_sockaddr *to);
+    int (*mso_recvfrom)(struct mn_socket *, struct os_mbuf **,
+      struct mn_sockaddr *from);
+
+    int (*mso_getsockopt)(struct mn_socket *, uint8_t level, uint8_t name,
+      void *val);
+    int (*mso_setsockopt)(struct mn_socket *, uint8_t level, uint8_t name,
+      void *val);
+
+    int (*mso_getsockname)(struct mn_socket *, struct mn_sockaddr *);
+    int (*mso_getpeername)(struct mn_socket *, struct mn_sockaddr *);
+};
+
+int mn_socket_ops_reg(const struct mn_socket_ops *ops);
+
+static inline void
+mn_socket_writable(struct mn_socket *s, int error)
+{
+    if (s->ms_cbs && s->ms_cbs->socket.writable) {
+        s->ms_cbs->socket.writable(s, error);
+    }
+}
+
+static inline void
+mn_socket_readable(struct mn_socket *s, int error)
+{
+    if (s->ms_cbs && s->ms_cbs->socket.readable) {
+        s->ms_cbs->socket.readable(s, error);
+    }
+}
+
+static inline int
+mn_socket_newconn(struct mn_socket *s, struct mn_socket *new)
+{
+    if (s->ms_cbs && s->ms_cbs->listen.newconn) {
+        return s->ms_cbs->listen.newconn(s, new);
+    } else {
+        return -1;
+    }
+}
+
+#endif /* __SYS_MN_SOCKET_OPS_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/mn_socket/pkg.yml b/sys/mn_socket/pkg.yml
new file mode 100644
index 0000000..0c9c064
--- /dev/null
+++ b/sys/mn_socket/pkg.yml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+pkg.name: sys/mn_socket
+pkg.description: Socket interface for Mynewt.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - socket
+    - IP
+
+pkg.deps:
+    - libs/os
+    - libs/util
+    - libs/testutil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/src/mn_socket.c
----------------------------------------------------------------------
diff --git a/sys/mn_socket/src/mn_socket.c b/sys/mn_socket/src/mn_socket.c
new file mode 100644
index 0000000..2a3602c
--- /dev/null
+++ b/sys/mn_socket/src/mn_socket.c
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <inttypes.h>
+#include <assert.h>
+
+#include <os/os.h>
+
+#include "mn_socket/mn_socket.h"
+#include "mn_socket/mn_socket_ops.h"
+
+/*
+ * Currently there can be just one provider of sockets.
+ */
+static const struct mn_socket_ops *mn_sock_tgt;
+
+int
+mn_socket_ops_reg(const struct mn_socket_ops *ops)
+{
+    if (mn_sock_tgt) {
+        /*
+         * XXXX for now.
+         */
+        return -1;
+    }
+    mn_sock_tgt = ops;
+    return 0;
+}
+
+int
+mn_socket(struct mn_socket **sp, uint8_t domain, uint8_t type, uint8_t proto)
+{
+    int rc;
+
+    *sp = NULL;
+    /*
+     * XXX Look up where socket should go.
+     */
+    if (!mn_sock_tgt) {
+        return MN_EINVAL;
+    }
+    rc = mn_sock_tgt->mso_create(sp, domain, type, proto);
+    if (*sp) {
+        (*sp)->ms_ops = mn_sock_tgt;
+    }
+    return rc;
+}
+
+int
+mn_bind(struct mn_socket *s, struct mn_sockaddr *addr)
+{
+    return s->ms_ops->mso_bind(s, addr);
+}
+
+int
+mn_connect(struct mn_socket *s, struct mn_sockaddr *addr)
+{
+    return s->ms_ops->mso_connect(s, addr);
+}
+
+int
+mn_listen(struct mn_socket *s, uint8_t qlen)
+{
+    return s->ms_ops->mso_listen(s, qlen);
+}
+
+int
+mn_recvfrom(struct mn_socket *s, struct os_mbuf **mp, struct mn_sockaddr *from)
+{
+    return s->ms_ops->mso_recvfrom(s, mp, from);
+}
+
+int
+mn_sendto(struct mn_socket *s, struct os_mbuf *m, struct mn_sockaddr *to)
+{
+    return s->ms_ops->mso_sendto(s, m, to);
+}
+
+int
+mn_getsockopt(struct mn_socket *s, uint8_t level, uint8_t name, void *val)
+{
+    return s->ms_ops->mso_getsockopt(s, level, name, val);
+}
+
+int
+mn_setsockopt(struct mn_socket *s, uint8_t level, uint8_t name, void *val)
+{
+    return s->ms_ops->mso_setsockopt(s, level, name, val);
+}
+
+int
+mn_getsockname(struct mn_socket *s, struct mn_sockaddr *addr)
+{
+    return s->ms_ops->mso_getsockname(s, addr);
+}
+
+int
+mn_getpeername(struct mn_socket *s, struct mn_sockaddr *addr)
+{
+    return s->ms_ops->mso_getpeername(s, addr);
+}
+
+int
+mn_close(struct mn_socket *s)
+{
+    return s->ms_ops->mso_close(s);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/src/mn_socket_aconv.c
----------------------------------------------------------------------
diff --git a/sys/mn_socket/src/mn_socket_aconv.c b/sys/mn_socket/src/mn_socket_aconv.c
new file mode 100644
index 0000000..5053eac
--- /dev/null
+++ b/sys/mn_socket/src/mn_socket_aconv.c
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <ctype.h>
+#include <os/queue.h>
+#include "mn_socket/mn_socket.h"
+
+int
+mn_inet_pton(int af, const char *src, void *dst)
+{
+    const char *ch_src;
+    uint8_t *ch_tgt;
+    int val;
+    int cnt;
+
+    if (af == MN_PF_INET) {
+        cnt = 0;
+        ch_tgt = dst;
+        val = 0;
+        for (ch_src = src; *ch_src; ch_src++) {
+            if (cnt > 4) {
+                return 0;
+            }
+            if (isdigit(*ch_src)) {
+                val = val * 10 + *ch_src - '0';
+                if (val > 255) {
+                    return 0;
+                }
+                *ch_tgt = val;
+            } else if (*ch_src == '.') {
+                ++cnt;
+                val = 0;
+                ch_tgt++;
+            } else {
+                return 0;
+            }
+        }
+        return 1;
+    } else {
+        return MN_EAFNOSUPPORT;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fbc2b69/sys/mn_socket/src/test/mn_sock_test.c
----------------------------------------------------------------------
diff --git a/sys/mn_socket/src/test/mn_sock_test.c b/sys/mn_socket/src/test/mn_sock_test.c
new file mode 100644
index 0000000..a8d9cc2
--- /dev/null
+++ b/sys/mn_socket/src/test/mn_sock_test.c
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <stdio.h>
+#include <string.h>
+
+#include <os/os.h>
+#include <testutil/testutil.h>
+
+#include "mn_socket/mn_socket.h"
+
+TEST_CASE(inet_pton_test)
+{
+    int rc;
+    uint8_t addr[8];
+    struct test_vec {
+        char *str;
+        uint8_t cmp[4];
+    };
+    struct test_vec ok_vec[] = {
+        { "1.1.1.1", { 1, 1, 1, 1 } },
+        { "1.2.3.4", { 1, 2, 3, 4 } },
+        { "010.001.255.255", { 10, 1, 255, 255 } },
+        { "001.002.005.006", { 1, 2, 5, 6 } }
+    };
+    struct test_vec invalid_vec[] = {
+        { "a.b.c.d" },
+        { "1a.b3.4.2" },
+        { "1.3.4.2a" },
+        { "1111.3.4.2" },
+        { "3.256.1.0" },
+    };
+    int i;
+
+    for (i = 0; i < sizeof(ok_vec) / sizeof(ok_vec[0]); i++) {
+        memset(addr, 0xa5, sizeof(addr));
+        rc = mn_inet_pton(MN_PF_INET, ok_vec[i].str, addr);
+        TEST_ASSERT(rc == 1);
+        TEST_ASSERT(!memcmp(ok_vec[i].cmp, addr, sizeof(uint32_t)));
+        TEST_ASSERT(addr[5] == 0xa5);
+    }
+    for (i = 0; i < sizeof(invalid_vec) / sizeof(invalid_vec[0]); i++) {
+        rc = mn_inet_pton(MN_PF_INET, invalid_vec[i].str, addr);
+        TEST_ASSERT(rc == 0);
+    }
+}
+
+TEST_SUITE(mn_socket_test_all)
+{
+    inet_pton_test();
+}
+
+#ifdef MYNEWT_SELFTEST
+
+int
+main(int argc, char **argv)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    mn_socket_test_all();
+
+    return tu_any_failed;
+}
+#endif
+


[4/4] incubator-mynewt-core git commit: BLE Host - gattc: dsc refers to chr val handle.

Posted by cc...@apache.org.
BLE Host - gattc: dsc refers to chr val handle.

Prior to this change, the corresponding characteristic's definition
handle was required to initiate descriptor discovery.  Now it is the
characteristic's *value* handle.

Rationale: an app likely doesn't care at all about characteristic
definition handles; it is the value handles that are interesting.  The
app should not need to calculate the definition handle from the value
handle just to discover descriptors.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c7c7c9c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c7c7c9c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c7c7c9c1

Branch: refs/heads/ble_hs_api
Commit: c7c7c9c18febecf9a36231c9e4dc416a40f684d3
Parents: e588bbb
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jul 13 10:47:15 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Jul 13 10:47:15 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c                 | 16 ++---
 net/nimble/host/src/test/ble_gatt_conn_test.c   |  4 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c | 72 ++++++++++----------
 3 files changed, 46 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c7c7c9c1/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 825365b..6a5e8ec 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -138,7 +138,7 @@ struct ble_gattc_proc {
         } disc_chr_uuid;
 
         struct {
-            uint16_t chr_def_handle;
+            uint16_t chr_val_handle;
             uint16_t prev_handle;
             uint16_t end_handle;
             ble_gatt_dsc_fn *cb;
@@ -447,8 +447,8 @@ static void
 ble_gattc_log_disc_all_dscs(struct ble_gattc_proc *proc)
 {
     ble_gattc_log_proc_init("discover all descriptors; ");
-    BLE_HS_LOG(INFO, "chr_def_handle=%d end_handle=%d\n",
-               proc->disc_all_dscs.chr_def_handle,
+    BLE_HS_LOG(INFO, "chr_val_handle=%d end_handle=%d\n",
+               proc->disc_all_dscs.chr_val_handle,
                proc->disc_all_dscs.end_handle);
 }
 
@@ -2255,7 +2255,7 @@ ble_gattc_disc_all_dscs_cb(struct ble_gattc_proc *proc, int status,
     } else {
         rc = proc->disc_all_dscs.cb(proc->conn_handle,
                                     ble_gattc_error(status, att_handle),
-                                    proc->disc_all_dscs.chr_def_handle,
+                                    proc->disc_all_dscs.chr_val_handle,
                                     dsc, proc->disc_all_dscs.cb_arg);
     }
 
@@ -2376,7 +2376,7 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc, int status)
  *
  * @param conn_handle           The connection over which to execute the
  *                                  procedure.
- * @param chr_def_handle        The handle of the characteristic definition
+ * @param chr_val_handle        The handle of the characteristic value
  *                                  attribute.
  * @param chr_end_handle        The last handle in the characteristic
  *                                  definition.
@@ -2388,7 +2388,7 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc, int status)
  * @return                      0 on success; nonzero on failure.
  */
 int
-ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_def_handle,
+ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
                         uint16_t chr_end_handle,
                         ble_gatt_dsc_fn *cb, void *cb_arg)
 {
@@ -2409,8 +2409,8 @@ ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_def_handle,
 
     proc->op = BLE_GATT_OP_DISC_ALL_DSCS;
     proc->conn_handle = conn_handle;
-    proc->disc_all_dscs.chr_def_handle = chr_def_handle;
-    proc->disc_all_dscs.prev_handle = chr_def_handle + 1;
+    proc->disc_all_dscs.chr_val_handle = chr_val_handle;
+    proc->disc_all_dscs.prev_handle = chr_val_handle;
     proc->disc_all_dscs.end_handle = chr_end_handle;
     proc->disc_all_dscs.cb = cb;
     proc->disc_all_dscs.cb_arg = cb_arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c7c7c9c1/net/nimble/host/src/test/ble_gatt_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_conn_test.c b/net/nimble/host/src/test/ble_gatt_conn_test.c
index 2617dfc..9441e20 100644
--- a/net/nimble/host/src/test/ble_gatt_conn_test.c
+++ b/net/nimble/host/src/test/ble_gatt_conn_test.c
@@ -428,12 +428,12 @@ TEST_CASE(ble_gatt_conn_test_disconnect)
 
     /* Connection 2. */
     disc_all_dscs_arg.exp_conn_handle = 2;
-    rc = ble_gattc_disc_all_dscs(2, 1, 0xffff,
+    rc = ble_gattc_disc_all_dscs(2, 3, 0xffff,
                                  ble_gatt_conn_test_disc_all_dscs_cb,
                                  &disc_all_dscs_arg);
 
     disc_chr_uuid_arg.exp_conn_handle = 2;
-    rc = ble_gattc_disc_chrs_by_uuid(2, 1, 0xffff, BLE_UUID16(0x2222),
+    rc = ble_gattc_disc_chrs_by_uuid(2, 2, 0xffff, BLE_UUID16(0x2222),
                                      ble_gatt_conn_test_disc_chr_uuid_cb,
                                      &disc_chr_uuid_arg);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c7c7c9c1/net/nimble/host/src/test/ble_gatt_disc_d_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_d_test.c b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
index 26e49be..048ecb7 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_d_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
@@ -28,7 +28,7 @@
 #include "ble_hs_test_util.h"
 
 struct ble_gatt_disc_d_test_dsc {
-    uint16_t chr_def_handle; /* 0 if last entry. */
+    uint16_t chr_val_handle; /* 0 if last entry. */
     uint16_t dsc_handle;
     uint8_t dsc_uuid128[16];
 };
@@ -74,7 +74,7 @@ ble_gatt_disc_d_test_misc_rx_rsp_once(
 
     off = BLE_ATT_FIND_INFO_RSP_BASE_SZ;
     for (i = 0; ; i++) {
-        if (dscs[i].chr_def_handle == 0) {
+        if (dscs[i].chr_val_handle == 0) {
             /* No more descriptors. */
             break;
         }
@@ -113,7 +113,7 @@ ble_gatt_disc_d_test_misc_rx_rsp(uint16_t conn_handle,
     int idx;
 
     idx = 0;
-    while (dscs[idx].chr_def_handle != 0) {
+    while (dscs[idx].chr_val_handle != 0) {
         count = ble_gatt_disc_d_test_misc_rx_rsp_once(conn_handle, dscs + idx);
         if (count == 0) {
             break;
@@ -140,9 +140,9 @@ ble_gatt_disc_d_test_misc_verify_dscs(struct ble_gatt_disc_d_test_dsc *dscs,
         stop_after = INT_MAX;
     }
 
-    for (i = 0; i < stop_after && dscs[i].chr_def_handle != 0; i++) {
-        TEST_ASSERT(dscs[i].chr_def_handle ==
-                    ble_gatt_disc_d_test_dscs[i].chr_def_handle);
+    for (i = 0; i < stop_after && dscs[i].chr_val_handle != 0; i++) {
+        TEST_ASSERT(dscs[i].chr_val_handle ==
+                    ble_gatt_disc_d_test_dscs[i].chr_val_handle);
         TEST_ASSERT(dscs[i].dsc_handle ==
                     ble_gatt_disc_d_test_dscs[i].dsc_handle);
         TEST_ASSERT(memcmp(dscs[i].dsc_uuid128,
@@ -157,7 +157,7 @@ ble_gatt_disc_d_test_misc_verify_dscs(struct ble_gatt_disc_d_test_dsc *dscs,
 static int
 ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
                              const struct ble_gatt_error *error,
-                             uint16_t chr_def_handle,
+                             uint16_t chr_val_handle,
                              const struct ble_gatt_dsc *dsc,
                              void *arg)
 {
@@ -175,7 +175,7 @@ ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
                           BLE_GATT_DISC_D_TEST_MAX_DSCS);
 
         dst = ble_gatt_disc_d_test_dscs + ble_gatt_disc_d_test_num_dscs++;
-        dst->chr_def_handle = chr_def_handle;
+        dst->chr_val_handle = chr_val_handle;
         dst->dsc_handle = dsc->handle;
         memcpy(dst->dsc_uuid128, dsc->uuid128, 16);
         break;
@@ -201,7 +201,7 @@ ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
 }
 
 static void
-ble_gatt_disc_d_test_misc_all(uint16_t chr_def_handle, uint16_t end_handle,
+ble_gatt_disc_d_test_misc_all(uint16_t chr_val_handle, uint16_t end_handle,
                               int stop_after,
                               struct ble_gatt_disc_d_test_dsc *dscs)
 {
@@ -214,7 +214,7 @@ ble_gatt_disc_d_test_misc_all(uint16_t chr_def_handle, uint16_t end_handle,
                                  NULL, NULL);
 
     num_left = stop_after;
-    rc = ble_gattc_disc_all_dscs(2, chr_def_handle, end_handle,
+    rc = ble_gattc_disc_all_dscs(2, chr_val_handle, end_handle,
                                  ble_gatt_disc_d_test_misc_cb, &num_left);
     TEST_ASSERT(rc == 0);
 
@@ -225,9 +225,9 @@ ble_gatt_disc_d_test_misc_all(uint16_t chr_def_handle, uint16_t end_handle,
 TEST_CASE(ble_gatt_disc_d_test_1)
 {
     /*** One 16-bit descriptor. */
-    ble_gatt_disc_d_test_misc_all(4, 10, 0,
+    ble_gatt_disc_d_test_misc_all(5, 10, 0,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 4,
+            .chr_val_handle = 5,
             .dsc_handle = 6,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1234),
         }, {
@@ -236,13 +236,13 @@ TEST_CASE(ble_gatt_disc_d_test_1)
     );
 
     /*** Two 16-bit descriptors. */
-    ble_gatt_disc_d_test_misc_all(49, 100, 0,
+    ble_gatt_disc_d_test_misc_all(50, 100, 0,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 51,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1111),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 52,
             .dsc_uuid128 = BLE_UUID16_ARR(0x2222),
         }, {
@@ -251,25 +251,25 @@ TEST_CASE(ble_gatt_disc_d_test_1)
     );
 
     /*** Five 16-bit descriptors. */
-    ble_gatt_disc_d_test_misc_all(49, 100, 0,
+    ble_gatt_disc_d_test_misc_all(50, 100, 0,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 51,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1111),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 52,
             .dsc_uuid128 = BLE_UUID16_ARR(0x2222),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 53,
             .dsc_uuid128 = BLE_UUID16_ARR(0x3333),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 54,
             .dsc_uuid128 = BLE_UUID16_ARR(0x4444),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 55,
             .dsc_uuid128 = BLE_UUID16_ARR(0x5555),
         }, {
@@ -278,25 +278,25 @@ TEST_CASE(ble_gatt_disc_d_test_1)
     );
 
     /*** Interleaved 16-bit and 128-bit descriptors. */
-    ble_gatt_disc_d_test_misc_all(49, 100, 0,
+    ble_gatt_disc_d_test_misc_all(50, 100, 0,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 51,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1111),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 52,
             .dsc_uuid128 = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 },
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 53,
             .dsc_uuid128 = BLE_UUID16_ARR(0x3333),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 54,
             .dsc_uuid128 = { 1,0,4,0,6,9,17,7,8,43,7,4,12,43,19,35 },
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 55,
             .dsc_uuid128 = BLE_UUID16_ARR(0x5555),
         }, {
@@ -305,13 +305,13 @@ TEST_CASE(ble_gatt_disc_d_test_1)
     );
 
     /*** Ends with final handle ID. */
-    ble_gatt_disc_d_test_misc_all(49, 52, 0,
+    ble_gatt_disc_d_test_misc_all(50, 52, 0,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 51,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1111),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 52,
             .dsc_uuid128 = BLE_UUID16_ARR(0x2222),
         }, {
@@ -320,25 +320,25 @@ TEST_CASE(ble_gatt_disc_d_test_1)
     );
 
     /*** Stop after two descriptors. */
-    ble_gatt_disc_d_test_misc_all(49, 100, 2,
+    ble_gatt_disc_d_test_misc_all(50, 100, 2,
         ((struct ble_gatt_disc_d_test_dsc[]) { {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 51,
             .dsc_uuid128 = BLE_UUID16_ARR(0x1111),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 52,
             .dsc_uuid128 = BLE_UUID16_ARR(0x2222),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 53,
             .dsc_uuid128 = BLE_UUID16_ARR(0x3333),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 54,
             .dsc_uuid128 = BLE_UUID16_ARR(0x4444),
         }, {
-            .chr_def_handle = 49,
+            .chr_val_handle = 50,
             .dsc_handle = 55,
             .dsc_uuid128 = BLE_UUID16_ARR(0x5555),
         }, {


[3/4] incubator-mynewt-core git commit: os - g_task_list initialized incorrectly.

Posted by cc...@apache.org.
os - g_task_list initialized incorrectly.

g_task_list is a STAILQ, but it was being externed and initialized as a
TAILQ.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e588bbba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e588bbba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e588bbba

Branch: refs/heads/ble_hs_api
Commit: e588bbbaebd32e4be78bbd26b6fa0b95d827578a
Parents: a5ab3ed
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 12 16:25:25 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jul 12 16:48:07 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/sim/os_arch_sim.c | 2 +-
 libs/os/src/os.c                   | 1 +
 libs/os/src/os_priv.h              | 5 ++++-
 libs/os/src/os_task.c              | 3 ++-
 4 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e588bbba/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 287b4fc..4970522 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -404,7 +404,7 @@ os_arch_os_init(void)
     mypid = getpid();
     g_current_task = NULL;
 
-    TAILQ_INIT(&g_os_task_list);
+    STAILQ_INIT(&g_os_task_list);
     TAILQ_INIT(&g_os_run_list);
     TAILQ_INIT(&g_os_sleep_list);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e588bbba/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index cbca765..90f972e 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -107,6 +107,7 @@ os_init(void)
     os_error_t err;
 
     TAILQ_INIT(&g_callout_list);
+    STAILQ_INIT(&g_os_task_list);
 
     err = os_arch_os_init();
     assert(err == OS_OK);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e588bbba/libs/os/src/os_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/os_priv.h b/libs/os/src/os_priv.h
index 9566546..ddc656b 100644
--- a/libs/os/src/os_priv.h
+++ b/libs/os/src/os_priv.h
@@ -20,12 +20,15 @@
 #ifndef H_OS_PRIV_
 #define H_OS_PRIV_
 
+#include "os/queue.h"
+
 TAILQ_HEAD(os_task_list, os_task);
 TAILQ_HEAD(os_callout_list, os_callout);
+STAILQ_HEAD(os_task_stailq, os_task);
 
 extern struct os_task_list g_os_run_list;
 extern struct os_task_list g_os_sleep_list;
-extern struct os_task_list g_os_task_list;
+extern struct os_task_stailq g_os_task_list;
 extern struct os_task *g_current_task;
 extern struct os_callout_list g_callout_list;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e588bbba/libs/os/src/os_task.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_task.c b/libs/os/src/os_task.c
index 55c1da2..e48fdf9 100644
--- a/libs/os/src/os_task.c
+++ b/libs/os/src/os_task.c
@@ -19,12 +19,13 @@
 
 
 #include "os/os.h"
+#include "os_priv.h"
 
 #include <string.h>
 
 uint8_t g_task_id;
 
-STAILQ_HEAD(, os_task) g_os_task_list = STAILQ_HEAD_INITIALIZER(g_os_task_list);
+struct os_task_stailq g_os_task_list;
 
 static void
 _clear_stack(os_stack_t *stack_bottom, int size)