2013-12-11 10:13:35

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 00/10] Refactoring bnep code to reduce redundancy

This patch set contains refactoring of bnep functionality, minor
fixes in android/pan and adding PAN profile NAP sdp record to
android.

Ravi kumar Veeramally (10):
bnep: Rename bnep_kill_connection to bnep_conndel
bnep: Rename send ctrl_rsp and make it global
bnep: Move bnep related calls to bnep.h|c
profiles/network/server: Delete function which does nothing
profiles/network: Move pan sdp record function bnep and make it global
android/pan: Remove channel unref which causing disconnection
android/pan: Fix missing cleanup calls
android/pan: Fix minor white space
android/pan: Free connected pan devices on profile unregister call
android/pan: Add PAN NAP sdp record fo server role

android/pan.c | 40 +++++++-
profiles/network/bnep.c | 209 ++++++++++++++++++++++++++++++++++++++++-
profiles/network/bnep.h | 10 +-
profiles/network/connection.c | 2 +-
profiles/network/manager.c | 2 -
profiles/network/server.c | 213 +-----------------------------------------
profiles/network/server.h | 1 -
7 files changed, 256 insertions(+), 221 deletions(-)

--
1.8.3.2



2013-12-11 13:33:00

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 00/10] Refactoring bnep code to reduce redundancy

Hi Ravi,

On Wed, Dec 11, 2013, Ravi kumar Veeramally wrote:
> bnep: Rename bnep_kill_connection to bnep_conndel
> bnep: Rename send ctrl_rsp and make it global
> bnep: Move bnep related calls to bnep.h|c
> profiles/network/server: Delete function which does nothing
> android/pan: Fix missing cleanup calls
> android/pan: Fix minor white space

The above patches have been applied. As we discussed offline, the others
were either dropped or need some extra work

Johan

2013-12-11 10:13:45

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 10/10] android/pan: Add PAN NAP sdp record fo server role

Adding PAN profile NAP SDP record on profile register call and
remove on unregister call.
---
android/pan.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/android/pan.c b/android/pan.c
index 29b0a54..a6a8e27 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -44,9 +44,12 @@
#include "utils.h"
#include "bluetooth.h"

+#define SVC_HINT_CAPTURING 0x08
+
static bdaddr_t adapter_addr;
GSList *devices = NULL;
uint8_t local_role = HAL_PAN_ROLE_NONE;
+static uint32_t record_id = 0;

struct pan_device {
char iface[16];
@@ -343,6 +346,7 @@ static const struct ipc_handler cmd_handlers[] = {

bool bt_pan_register(const bdaddr_t *addr)
{
+ sdp_record_t *rec = NULL;
int err;

DBG("");
@@ -355,6 +359,21 @@ bool bt_pan_register(const bdaddr_t *addr)
return false;
}

+ rec = pan_record("bnepnap", BNEP_SVC_NAP, TRUE);
+ if (!rec) {
+ bnep_cleanup();
+ return false;
+ }
+
+ if (bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
+ error("Failed to register on PAN record");
+ sdp_record_free(rec);
+ bnep_cleanup();
+ return false;
+ }
+
+ record_id = rec->handle;
+
ipc_register(HAL_SERVICE_ID_PAN, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));

@@ -373,6 +392,8 @@ void bt_pan_unregister(void)
{
DBG("");

+ bt_adapter_remove_record(record_id);
+
g_slist_foreach(devices, free_pan_devices, NULL);
devices = NULL;
bnep_cleanup();
--
1.8.3.2


2013-12-11 10:13:43

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 08/10] android/pan: Fix minor white space

---
android/pan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/pan.c b/android/pan.c
index 1ed7b04..0783357 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -257,7 +257,7 @@ static void bt_pan_connect(const void *buf, uint16_t len)
devices = g_slist_append(devices, dev);
bt_pan_notify_conn_state(dev, HAL_PAN_STATE_CONNECTING);

- status = HAL_STATUS_SUCCESS;
+ status = HAL_STATUS_SUCCESS;

failed:
ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_CONNECT, status);
--
1.8.3.2


2013-12-11 10:13:42

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 07/10] android/pan: Fix missing cleanup calls

---
android/pan.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/android/pan.c b/android/pan.c
index a9557a0..1ed7b04 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -128,6 +128,8 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,

DBG("%s disconnected", dev->iface);

+ bnep_if_down(dev->iface);
+ bnep_conndel(&dev->dst);
bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
pan_device_free(dev);

@@ -142,6 +144,7 @@ static void bnep_conn_cb(GIOChannel *chan, char *iface, int err, void *data)

if (err < 0) {
error("bnep connect req failed: %s", strerror(-err));
+ bnep_conndel(&dev->dst);
bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
pan_device_free(dev);
return;
--
1.8.3.2


2013-12-11 10:13:44

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 09/10] android/pan: Free connected pan devices on profile unregister call

---
android/pan.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/android/pan.c b/android/pan.c
index 0783357..29b0a54 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -361,10 +361,20 @@ bool bt_pan_register(const bdaddr_t *addr)
return true;
}

+static void free_pan_devices(gpointer data, gpointer user_data)
+{
+ struct pan_device *dev = data;
+
+ bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+ pan_device_free(dev);
+}
+
void bt_pan_unregister(void)
{
DBG("");

+ g_slist_foreach(devices, free_pan_devices, NULL);
+ devices = NULL;
bnep_cleanup();

ipc_unregister(HAL_SERVICE_ID_PAN);
--
1.8.3.2


2013-12-11 10:13:41

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 06/10] android/pan: Remove channel unref which causing disconnection

Channel unreferencing here causing calling watchdog_cb and eventually
connection is dismissed immediately. Channel is already freed
in bnep.c:free_bnep_connect().
---
android/pan.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index f74f1a7..a9557a0 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -156,8 +156,6 @@ static void bnep_conn_cb(GIOChannel *chan, char *iface, int err, void *data)

dev->watch = g_io_add_watch(chan, G_IO_ERR | G_IO_HUP | G_IO_NVAL,
bnep_watchdog_cb, dev);
- g_io_channel_unref(dev->io);
- dev->io = NULL;
}

static void connect_cb(GIOChannel *chan, GError *err, gpointer data)
--
1.8.3.2


2013-12-11 10:13:39

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 04/10] profiles/network/server: Delete function which does nothing

---
profiles/network/manager.c | 2 --
profiles/network/server.c | 4 ----
profiles/network/server.h | 1 -
3 files changed, 7 deletions(-)

diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 8ac2dec..47aebcb 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -200,8 +200,6 @@ static int network_init(void)

static void network_exit(void)
{
- server_exit();
-
btd_profile_unregister(&panu_profile);
btd_profile_unregister(&gn_profile);
btd_profile_unregister(&nap_profile);
diff --git a/profiles/network/server.c b/profiles/network/server.c
index cf34932..73741ec 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -493,10 +493,6 @@ int server_init(gboolean secure)
return 0;
}

-void server_exit(void)
-{
-}
-
static uint32_t register_server_record(struct network_server *ns)
{
sdp_record_t *record;
diff --git a/profiles/network/server.h b/profiles/network/server.h
index 2edd342..a76e6f7 100644
--- a/profiles/network/server.h
+++ b/profiles/network/server.h
@@ -22,6 +22,5 @@
*/

int server_init(gboolean secure);
-void server_exit(void);
int server_register(struct btd_adapter *adapter, uint16_t id);
int server_unregister(struct btd_adapter *adapter, uint16_t id);
--
1.8.3.2


2013-12-11 10:13:37

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 02/10] bnep: Rename send ctrl_rsp and make it global

Renaming send_bnep_ctrl_rsp to bnep_send_ctrl_rsp and moving
to bnep.h. It is required in android/*.
---
profiles/network/bnep.c | 11 +++++++++++
profiles/network/bnep.h | 2 ++
profiles/network/server.c | 13 +------------
3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index aa980a2..57dfbf9 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -464,3 +464,14 @@ int bnep_del_from_bridge(const char *devname, const char *bridge)

return 0;
}
+
+ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp)
+{
+ struct bnep_control_rsp rsp;
+
+ rsp.type = type;
+ rsp.ctrl = ctrl;
+ rsp.resp = htons(resp);
+
+ return send(sk, &rsp, sizeof(rsp), 0);
+}
diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h
index 1905a98..dea0319 100644
--- a/profiles/network/bnep.h
+++ b/profiles/network/bnep.h
@@ -39,3 +39,5 @@ typedef void (*bnep_connect_cb) (GIOChannel *chan, char *iface, int err,
void *data);
int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb,
void *data);
+
+ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp);
\ No newline at end of file
diff --git a/profiles/network/server.c b/profiles/network/server.c
index c777cc1..296ddd8 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -251,17 +251,6 @@ static sdp_record_t *server_record_new(const char *name, uint16_t id)
return record;
}

-static ssize_t send_bnep_ctrl_rsp(int sk, uint16_t val)
-{
- struct bnep_control_rsp rsp;
-
- rsp.type = BNEP_CONTROL;
- rsp.ctrl = BNEP_SETUP_CONN_RSP;
- rsp.resp = htons(val);
-
- return send(sk, &rsp, sizeof(rsp), 0);
-}
-
static int server_connadd(struct network_server *ns,
struct network_session *session,
uint16_t dst_role)
@@ -462,7 +451,7 @@ static gboolean bnep_setup(GIOChannel *chan,
rsp = BNEP_SUCCESS;

reply:
- send_bnep_ctrl_rsp(sk, rsp);
+ bnep_send_ctrl_rsp(sk, BNEP_CONTROL, BNEP_SETUP_CONN_RSP, rsp);

return FALSE;
}
--
1.8.3.2


2013-12-11 10:13:38

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 03/10] bnep: Move bnep related calls to bnep.h|c

Moving bnep related calls to bnep.h|c to reduce redundancy
while using same in android/*.
---
profiles/network/bnep.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++
profiles/network/bnep.h | 5 +++-
profiles/network/server.c | 66 ----------------------------------------------
3 files changed, 71 insertions(+), 67 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 57dfbf9..08037e6 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -475,3 +475,70 @@ ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp)

return send(sk, &rsp, sizeof(rsp), 0);
}
+
+uint16_t bnep_setup_chk(uint16_t dst, uint16_t src)
+{
+ /* Allowed PAN Profile scenarios */
+ switch (dst) {
+ case BNEP_SVC_NAP:
+ case BNEP_SVC_GN:
+ if (src == BNEP_SVC_PANU)
+ return 0;
+ return BNEP_CONN_INVALID_SRC;
+ case BNEP_SVC_PANU:
+ if (src == BNEP_SVC_PANU || src == BNEP_SVC_GN ||
+ src == BNEP_SVC_NAP)
+ return 0;
+
+ return BNEP_CONN_INVALID_SRC;
+ }
+
+ return BNEP_CONN_INVALID_DST;
+}
+
+uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,
+ uint16_t *src)
+{
+ const uint8_t bt_base[] = { 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
+ 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
+ uint8_t *dest, *source;
+ uint32_t val;
+
+ dest = req->service;
+ source = req->service + req->uuid_size;
+
+ switch (req->uuid_size) {
+ case 2: /* UUID16 */
+ *dst = bt_get_be16(dest);
+ *src = bt_get_be16(source);
+ break;
+ case 16: /* UUID128 */
+ /* Check that the bytes in the UUID, except the service ID
+ * itself, are correct. The service ID is checked in
+ * bnep_setup_chk(). */
+ if (memcmp(&dest[4], bt_base, sizeof(bt_base)) != 0)
+ return BNEP_CONN_INVALID_DST;
+ if (memcmp(&source[4], bt_base, sizeof(bt_base)) != 0)
+ return BNEP_CONN_INVALID_SRC;
+
+ /* Intentional no-break */
+
+ case 4: /* UUID32 */
+ val = bt_get_be32(dest);
+ if (val > 0xffff)
+ return BNEP_CONN_INVALID_DST;
+
+ *dst = val;
+
+ val = bt_get_be32(source);
+ if (val > 0xffff)
+ return BNEP_CONN_INVALID_SRC;
+
+ *src = val;
+ break;
+ default:
+ return BNEP_CONN_INVALID_SVC;
+ }
+
+ return BNEP_SUCCESS;
+}
diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h
index dea0319..dd22c40 100644
--- a/profiles/network/bnep.h
+++ b/profiles/network/bnep.h
@@ -40,4 +40,7 @@ typedef void (*bnep_connect_cb) (GIOChannel *chan, char *iface, int err,
int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb,
void *data);

-ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp);
\ No newline at end of file
+ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp);
+uint16_t bnep_setup_chk(uint16_t dst_role, uint16_t src_role);
+uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,
+ uint16_t *src);
diff --git a/profiles/network/server.c b/profiles/network/server.c
index 296ddd8..cf34932 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -280,72 +280,6 @@ static int server_connadd(struct network_server *ns,
return 0;
}

-static uint16_t bnep_setup_chk(uint16_t dst_role, uint16_t src_role)
-{
- /* Allowed PAN Profile scenarios */
- switch (dst_role) {
- case BNEP_SVC_NAP:
- case BNEP_SVC_GN:
- if (src_role == BNEP_SVC_PANU)
- return 0;
- return BNEP_CONN_INVALID_SRC;
- case BNEP_SVC_PANU:
- if (src_role == BNEP_SVC_PANU ||
- src_role == BNEP_SVC_GN ||
- src_role == BNEP_SVC_NAP)
- return 0;
-
- return BNEP_CONN_INVALID_SRC;
- }
-
- return BNEP_CONN_INVALID_DST;
-}
-
-static uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req,
- uint16_t *dst_role, uint16_t *src_role)
-{
- const uint8_t bt_base[] = { 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
- 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
- uint8_t *dest, *source;
- uint32_t val;
-
- dest = req->service;
- source = req->service + req->uuid_size;
-
- switch (req->uuid_size) {
- case 2: /* UUID16 */
- *dst_role = bt_get_be16(dest);
- *src_role = bt_get_be16(source);
- break;
- case 16: /* UUID128 */
- /* Check that the bytes in the UUID, except the service ID
- * itself, are correct. The service ID is checked in
- * bnep_setup_chk(). */
- if (memcmp(&dest[4], bt_base, sizeof(bt_base)) != 0)
- return BNEP_CONN_INVALID_DST;
- if (memcmp(&source[4], bt_base, sizeof(bt_base)) != 0)
- return BNEP_CONN_INVALID_SRC;
-
- /* Intentional no-break */
-
- case 4: /* UUID32 */
- val = bt_get_be32(dest);
- if (val > 0xffff)
- return BNEP_CONN_INVALID_DST;
- *dst_role = val;
-
- val = bt_get_be32(source);
- if (val > 0xffff)
- return BNEP_CONN_INVALID_SRC;
- *src_role = val;
- break;
- default:
- return BNEP_CONN_INVALID_SVC;
- }
-
- return BNEP_SUCCESS;
-}
-
static void session_free(void *data)
{
struct network_session *session = data;
--
1.8.3.2


2013-12-11 10:13:40

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 05/10] profiles/network: Move pan sdp record function bnep and make it global

Moving pan sdp record function bnep, it is required in android/pan.
Even though it is not exactly related to bnep, but bnep.h|c is dbus
free files and shared with android/*.
---
profiles/network/bnep.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++
profiles/network/bnep.h | 2 +
profiles/network/server.c | 128 +--------------------------------------------
3 files changed, 132 insertions(+), 127 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 08037e6..bbccd87 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -39,6 +39,8 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/bnep.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>

#include <glib.h>

@@ -542,3 +544,130 @@ uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,

return BNEP_SUCCESS;
}
+
+sdp_record_t *pan_record(const char *name, uint16_t id, gboolean security)
+{
+ sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
+ uuid_t root_uuid, pan, l2cap, bnep;
+ sdp_profile_desc_t profile[1];
+ sdp_list_t *proto[2];
+ sdp_data_t *v, *p;
+ uint16_t psm = BNEP_PSM, version = 0x0100;
+ uint16_t security_desc = (security ? 0x0001 : 0x0000);
+ uint16_t net_access_type = 0xfffe;
+ uint32_t max_net_access_rate = 0;
+ const char *desc = "Network service";
+ sdp_record_t *record;
+
+ record = sdp_record_alloc();
+ if (!record)
+ return NULL;
+
+ record->attrlist = NULL;
+ record->pattern = NULL;
+
+ switch (id) {
+ case BNEP_SVC_NAP:
+ sdp_uuid16_create(&pan, NAP_SVCLASS_ID);
+ svclass = sdp_list_append(NULL, &pan);
+ sdp_set_service_classes(record, svclass);
+
+ sdp_uuid16_create(&profile[0].uuid, NAP_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, &profile[0]);
+ sdp_set_profile_descs(record, pfseq);
+
+ sdp_set_info_attr(record, name, NULL, desc);
+
+ sdp_attr_add_new(record, SDP_ATTR_NET_ACCESS_TYPE,
+ SDP_UINT16, &net_access_type);
+ sdp_attr_add_new(record, SDP_ATTR_MAX_NET_ACCESSRATE,
+ SDP_UINT32, &max_net_access_rate);
+ break;
+ case BNEP_SVC_GN:
+ sdp_uuid16_create(&pan, GN_SVCLASS_ID);
+ svclass = sdp_list_append(NULL, &pan);
+ sdp_set_service_classes(record, svclass);
+
+ sdp_uuid16_create(&profile[0].uuid, GN_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, &profile[0]);
+ sdp_set_profile_descs(record, pfseq);
+
+ sdp_set_info_attr(record, name, NULL, desc);
+ break;
+ case BNEP_SVC_PANU:
+ sdp_uuid16_create(&pan, PANU_SVCLASS_ID);
+ svclass = sdp_list_append(NULL, &pan);
+ sdp_set_service_classes(record, svclass);
+
+ sdp_uuid16_create(&profile[0].uuid, PANU_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, &profile[0]);
+ sdp_set_profile_descs(record, pfseq);
+
+ sdp_set_info_attr(record, name, NULL, desc);
+ break;
+ default:
+ sdp_record_free(record);
+ return NULL;
+ }
+
+ sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
+ root = sdp_list_append(NULL, &root_uuid);
+ sdp_set_browse_groups(record, root);
+
+ sdp_uuid16_create(&l2cap, L2CAP_UUID);
+ proto[0] = sdp_list_append(NULL, &l2cap);
+ p = sdp_data_alloc(SDP_UINT16, &psm);
+ proto[0] = sdp_list_append(proto[0], p);
+ apseq = sdp_list_append(NULL, proto[0]);
+
+ sdp_uuid16_create(&bnep, BNEP_UUID);
+ proto[1] = sdp_list_append(NULL, &bnep);
+ v = sdp_data_alloc(SDP_UINT16, &version);
+ proto[1] = sdp_list_append(proto[1], v);
+
+ /* Supported protocols */
+ {
+ uint16_t ptype[] = {
+ 0x0800, /* IPv4 */
+ 0x0806, /* ARP */
+ };
+ sdp_data_t *head, *pseq;
+ int p;
+
+ for (p = 0, head = NULL; p < 2; p++) {
+ sdp_data_t *data = sdp_data_alloc(SDP_UINT16,
+ &ptype[p]);
+ if (head)
+ sdp_seq_append(head, data);
+ else
+ head = data;
+ }
+ pseq = sdp_data_alloc(SDP_SEQ16, head);
+ proto[1] = sdp_list_append(proto[1], pseq);
+ }
+
+ apseq = sdp_list_append(apseq, proto[1]);
+
+ aproto = sdp_list_append(NULL, apseq);
+ sdp_set_access_protos(record, aproto);
+
+ sdp_add_lang_attr(record);
+
+ sdp_attr_add_new(record, SDP_ATTR_SECURITY_DESC,
+ SDP_UINT16, &security_desc);
+
+ sdp_data_free(p);
+ sdp_data_free(v);
+ sdp_list_free(apseq, NULL);
+ sdp_list_free(root, NULL);
+ sdp_list_free(aproto, NULL);
+ sdp_list_free(proto[0], NULL);
+ sdp_list_free(proto[1], NULL);
+ sdp_list_free(svclass, NULL);
+ sdp_list_free(pfseq, NULL);
+
+ return record;
+}
diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h
index dd22c40..4f1f812 100644
--- a/profiles/network/bnep.h
+++ b/profiles/network/bnep.h
@@ -44,3 +44,5 @@ ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp);
uint16_t bnep_setup_chk(uint16_t dst_role, uint16_t src_role);
uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,
uint16_t *src);
+
+sdp_record_t *pan_record(const char *name, uint16_t id, gboolean security);
diff --git a/profiles/network/server.c b/profiles/network/server.c
index 73741ec..95564c6 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -125,132 +125,6 @@ static struct network_server *find_server_by_uuid(GSList *list,
return NULL;
}

-static sdp_record_t *server_record_new(const char *name, uint16_t id)
-{
- sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
- uuid_t root_uuid, pan, l2cap, bnep;
- sdp_profile_desc_t profile[1];
- sdp_list_t *proto[2];
- sdp_data_t *v, *p;
- uint16_t psm = BNEP_PSM, version = 0x0100;
- uint16_t security_desc = (security ? 0x0001 : 0x0000);
- uint16_t net_access_type = 0xfffe;
- uint32_t max_net_access_rate = 0;
- const char *desc = "Network service";
- sdp_record_t *record;
-
- record = sdp_record_alloc();
- if (!record)
- return NULL;
-
- record->attrlist = NULL;
- record->pattern = NULL;
-
- switch (id) {
- case BNEP_SVC_NAP:
- sdp_uuid16_create(&pan, NAP_SVCLASS_ID);
- svclass = sdp_list_append(NULL, &pan);
- sdp_set_service_classes(record, svclass);
-
- sdp_uuid16_create(&profile[0].uuid, NAP_PROFILE_ID);
- profile[0].version = 0x0100;
- pfseq = sdp_list_append(NULL, &profile[0]);
- sdp_set_profile_descs(record, pfseq);
-
- sdp_set_info_attr(record, name, NULL, desc);
-
- sdp_attr_add_new(record, SDP_ATTR_NET_ACCESS_TYPE,
- SDP_UINT16, &net_access_type);
- sdp_attr_add_new(record, SDP_ATTR_MAX_NET_ACCESSRATE,
- SDP_UINT32, &max_net_access_rate);
- break;
- case BNEP_SVC_GN:
- sdp_uuid16_create(&pan, GN_SVCLASS_ID);
- svclass = sdp_list_append(NULL, &pan);
- sdp_set_service_classes(record, svclass);
-
- sdp_uuid16_create(&profile[0].uuid, GN_PROFILE_ID);
- profile[0].version = 0x0100;
- pfseq = sdp_list_append(NULL, &profile[0]);
- sdp_set_profile_descs(record, pfseq);
-
- sdp_set_info_attr(record, name, NULL, desc);
- break;
- case BNEP_SVC_PANU:
- sdp_uuid16_create(&pan, PANU_SVCLASS_ID);
- svclass = sdp_list_append(NULL, &pan);
- sdp_set_service_classes(record, svclass);
-
- sdp_uuid16_create(&profile[0].uuid, PANU_PROFILE_ID);
- profile[0].version = 0x0100;
- pfseq = sdp_list_append(NULL, &profile[0]);
- sdp_set_profile_descs(record, pfseq);
-
- sdp_set_info_attr(record, name, NULL, desc);
- break;
- default:
- sdp_record_free(record);
- return NULL;
- }
-
- sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
- root = sdp_list_append(NULL, &root_uuid);
- sdp_set_browse_groups(record, root);
-
- sdp_uuid16_create(&l2cap, L2CAP_UUID);
- proto[0] = sdp_list_append(NULL, &l2cap);
- p = sdp_data_alloc(SDP_UINT16, &psm);
- proto[0] = sdp_list_append(proto[0], p);
- apseq = sdp_list_append(NULL, proto[0]);
-
- sdp_uuid16_create(&bnep, BNEP_UUID);
- proto[1] = sdp_list_append(NULL, &bnep);
- v = sdp_data_alloc(SDP_UINT16, &version);
- proto[1] = sdp_list_append(proto[1], v);
-
- /* Supported protocols */
- {
- uint16_t ptype[] = {
- 0x0800, /* IPv4 */
- 0x0806, /* ARP */
- };
- sdp_data_t *head, *pseq;
- int p;
-
- for (p = 0, head = NULL; p < 2; p++) {
- sdp_data_t *data = sdp_data_alloc(SDP_UINT16, &ptype[p]);
- if (head)
- sdp_seq_append(head, data);
- else
- head = data;
- }
- pseq = sdp_data_alloc(SDP_SEQ16, head);
- proto[1] = sdp_list_append(proto[1], pseq);
- }
-
- apseq = sdp_list_append(apseq, proto[1]);
-
- aproto = sdp_list_append(NULL, apseq);
- sdp_set_access_protos(record, aproto);
-
- sdp_add_lang_attr(record);
-
- sdp_attr_add_new(record, SDP_ATTR_SECURITY_DESC,
- SDP_UINT16, &security_desc);
-
- sdp_data_free(p);
- sdp_data_free(v);
- sdp_list_free(apseq, NULL);
- sdp_list_free(root, NULL);
- sdp_list_free(aproto, NULL);
- sdp_list_free(proto[0], NULL);
- sdp_list_free(proto[1], NULL);
- sdp_list_free(svclass, NULL);
- sdp_list_free(pfseq, NULL);
-
- return record;
-}
-
static int server_connadd(struct network_server *ns,
struct network_session *session,
uint16_t dst_role)
@@ -497,7 +371,7 @@ static uint32_t register_server_record(struct network_server *ns)
{
sdp_record_t *record;

- record = server_record_new(ns->name, ns->id);
+ record = pan_record(ns->name, ns->id, security);
if (!record) {
error("Unable to allocate new service record");
return 0;
--
1.8.3.2


2013-12-11 10:13:36

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 01/10] bnep: Rename bnep_kill_connection to bnep_conndel

Renaming bnep_kill_connection to bnep_conndel to maintain
consistency with bnep_connadd function name.
---
android/pan.c | 2 +-
profiles/network/bnep.c | 2 +-
profiles/network/bnep.h | 3 +--
profiles/network/connection.c | 2 +-
profiles/network/server.c | 2 +-
5 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index 6b098b2..f74f1a7 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -288,7 +288,7 @@ static void bt_pan_disconnect(const void *buf, uint16_t len)
}

bnep_if_down(dev->iface);
- bnep_kill_connection(&dst);
+ bnep_conndel(&dst);

bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
pan_device_free(dev);
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 912c0c2..aa980a2 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -160,7 +160,7 @@ int bnep_cleanup(void)
return 0;
}

-int bnep_kill_connection(const bdaddr_t *dst)
+int bnep_conndel(const bdaddr_t *dst)
{
struct bnep_conndel_req req;

diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h
index 9043e46..1905a98 100644
--- a/profiles/network/bnep.h
+++ b/profiles/network/bnep.h
@@ -28,9 +28,8 @@ uint16_t bnep_service_id(const char *svc);
const char *bnep_uuid(uint16_t id);
const char *bnep_name(uint16_t id);

-int bnep_kill_connection(const bdaddr_t *dst);
-
int bnep_connadd(int sk, uint16_t role, char *dev);
+int bnep_conndel(const bdaddr_t *dst);
int bnep_if_up(const char *devname);
int bnep_if_down(const char *devname);
int bnep_add_to_bridge(const char *devname, const char *bridge);
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 9aff319..fb3e1ce 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -171,7 +171,7 @@ static void connection_destroy(DBusConnection *conn, void *user_data)

if (nc->state == CONNECTED) {
bnep_if_down(nc->dev);
- bnep_kill_connection(device_get_address(nc->peer->device));
+ bnep_conndel(device_get_address(nc->peer->device));
} else if (nc->io)
cancel_connection(nc, -EIO);
}
diff --git a/profiles/network/server.c b/profiles/network/server.c
index b3aab11..c777cc1 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -608,7 +608,7 @@ static void server_remove_sessions(struct network_server *ns)
bnep_del_from_bridge(session->dev, ns->bridge);
bnep_if_down(session->dev);

- bnep_kill_connection(&session->dst);
+ bnep_conndel(&session->dst);
}

g_slist_free_full(ns->sessions, session_free);
--
1.8.3.2