Hi all,
this patch allows to process several response statuses and execute specified
handlers. Currently it's used in active scanning when you may receive a
beacon or end_of_scan signals.
Thank you,
Alexander
From 8516cb53c66ba883da9ceb30146479728d097cb6 Mon Sep 17 00:00:00 2001
From: Alexander Smirnov <[email protected]>
Date: Fri, 17 Jun 2011 12:34:04 +0400
Subject: [PATCH] Add response callback more flexible.
Signed-off-by: Alexander Smirnov <[email protected]>
---
src/iz-common.c | 10 +++++++-
src/iz-mac.c | 59 +++++++++++++++++++++++++++++++++++++++++++++---------
src/iz-phy.c | 44 +++++++++++++++++++++++++++++++++-------
src/iz.c | 10 +++++++-
src/iz.h | 13 +++++++++--
5 files changed, 111 insertions(+), 25 deletions(-)
diff --git a/src/iz-common.c b/src/iz-common.c
index 899b4d1..75c03ad 100644
--- a/src/iz-common.c
+++ b/src/iz-common.c
@@ -147,6 +147,13 @@ static iz_res_t event_finish(struct iz_cmd *cmd)
return IZ_CONT_OK;
}
+static struct iz_cmd_event monitor_response_event[] = {
+ {
+ .call = event_response,
+ .nl = __IEEE802154_CMD_MAX,
+ },
+ { 0, 0 },
+};
/* Command descriptors */
const struct iz_module iz_common = {
@@ -163,9 +170,8 @@ const struct iz_module iz_common = {
.usage = "[iface]",
.doc = "Monitor events from the kernel (^C to stop).",
.parse = event_parse,
- .response = event_response,
+ .response = monitor_response_event,
.finish = event_finish,
- .listener = 1,
},
{}}
};
diff --git a/src/iz-mac.c b/src/iz-mac.c
index 9bf9d0a..4a91895 100644
--- a/src/iz-mac.c
+++ b/src/iz-mac.c
@@ -109,6 +109,13 @@ static iz_res_t scan_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, struc
int i;
uint8_t edl[27];
+ if (ghdr->cmd == 21) {
+ printf("Found beacon:\n\tShort addr: %d\n\tPAN id: %d\n",
+ nla_get_u16(attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]),
+ nla_get_u16(attrs[IEEE802154_ATTR_COORD_PAN_ID]));
+ return IZ_CONT_OK;
+ }
+
if (!attrs[IEEE802154_ATTR_DEV_INDEX] ||
!attrs[IEEE802154_ATTR_STATUS] ||
!attrs[IEEE802154_ATTR_SCAN_TYPE])
@@ -131,8 +138,8 @@ static iz_res_t scan_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, struc
return IZ_STOP_OK;
case IEEE802154_MAC_SCAN_ACTIVE:
- printf("Started active (beacons) scan...\n");
- return IZ_CONT_OK;
+ printf("Finished active (beacons) scan...\n");
+ return IZ_STOP_OK;
default:
printf("Unsupported scan type: %d\n", type);
break;
@@ -141,6 +148,18 @@ static iz_res_t scan_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, struc
return IZ_STOP_OK;
}
+static struct iz_cmd_event scan_response_event[] = {
+ {
+ .call = scan_response,
+ .nl = IEEE802154_SCAN_CONF,
+ },
+ {
+ .call = scan_response,
+ .nl = IEEE802154_BEACON_NOTIFY_INDIC,
+ },
+ { 0, 0 },
+};
+
/******************/
/* LIST handling */
/******************/
@@ -226,6 +245,14 @@ static iz_res_t list_finish(struct iz_cmd *cmd)
return IZ_STOP_OK;
}
+static struct iz_cmd_event list_response_event[] = {
+ {
+ .call = list_response,
+ .nl = IEEE802154_LIST_IFACE,
+ },
+ { 0, 0 },
+};
+
/************************/
/* ASSOCIATE handling */
/************************/
@@ -321,6 +348,14 @@ static iz_res_t assoc_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, stru
return IZ_STOP_OK;
}
+static struct iz_cmd_event assoc_response_event[] = {
+ {
+ .call = assoc_response,
+ .nl = IEEE802154_ASSOCIATE_CONF,
+ },
+ { 0, 0 },
+};
+
/*************************/
/* DISASSOCIATE handling */
/*************************/
@@ -390,6 +425,14 @@ static iz_res_t disassoc_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, s
return IZ_STOP_OK;
}
+static struct iz_cmd_event disassoc_response_event[] = {
+ {
+ .call = disassoc_response,
+ .nl = IEEE802154_DISASSOCIATE_CONF,
+ },
+ { 0, 0 },
+};
+
const struct iz_module iz_mac = {
.name = "MAC 802.15.4",
.commands = {
@@ -398,40 +441,36 @@ const struct iz_module iz_mac = {
.usage = "<iface> <ed|active|passive|orphan> <channels> <duration>",
.doc = "Perform network scanning on specified channels.",
.nl_cmd = IEEE802154_SCAN_REQ,
- .nl_resp = IEEE802154_SCAN_CONF,
.parse = scan_parse,
.request = scan_request,
- .response = scan_response,
+ .response = scan_response_event,
},
{
.name = "assoc",
.usage = "<iface> <pan> <coord> <chan> ['short']",
.doc = "Associate with a given network via coordinator.",
.nl_cmd = IEEE802154_ASSOCIATE_REQ,
- .nl_resp = IEEE802154_ASSOCIATE_CONF,
.parse = assoc_parse,
.request = assoc_request,
- .response = assoc_response,
+ .response = assoc_response_event,
},
{
.name = "disassoc",
.usage = "<iface> <addr> <reason>",
.doc = "Disassociate from a network.",
.nl_cmd = IEEE802154_DISASSOCIATE_REQ,
- .nl_resp = IEEE802154_DISASSOCIATE_CONF,
.parse = disassoc_parse,
.request = disassoc_request,
- .response = disassoc_response,
+ .response = disassoc_response_event,
},
{
.name = "list",
.usage = "[iface]",
.doc = "List interface(s).",
.nl_cmd = IEEE802154_LIST_IFACE,
- .nl_resp = IEEE802154_LIST_IFACE,
.parse = list_parse,
.request = list_request,
- .response = list_response,
+ .response = list_response_event,
.finish = list_finish,
},
{}}
diff --git a/src/iz-phy.c b/src/iz-phy.c
index 3c51fb8..123c541 100644
--- a/src/iz-phy.c
+++ b/src/iz-phy.c
@@ -127,6 +127,14 @@ static iz_res_t list_phy_finish(struct iz_cmd *cmd)
return IZ_STOP_OK;
}
+static struct iz_cmd_event list_phy_response_event[] = {
+ {
+ .call = list_phy_response,
+ .nl = IEEE802154_LIST_PHY,
+ },
+ { 0, 0 },
+};
+
/******************
* ADD handling *
******************/
@@ -185,6 +193,14 @@ static iz_res_t add_phy_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, st
return IZ_STOP_OK;
}
+static struct iz_cmd_event add_phy_response_event[] = {
+ {
+ .call = add_phy_response,
+ .nl = IEEE802154_ADD_IFACE,
+ },
+ { 0, 0 },
+};
+
/********************
* MONITOR handling *
********************/
@@ -230,6 +246,14 @@ static iz_res_t monitor_phy_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr
return IZ_STOP_OK;
}
+static struct iz_cmd_event monitor_phy_response_event[] = {
+ {
+ .call = monitor_phy_response,
+ .nl = IEEE802154_ADD_IFACE,
+ },
+ { 0, 0 },
+};
+
/******************
* DEL handling *
******************/
@@ -278,6 +302,14 @@ static iz_res_t del_phy_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, st
return IZ_STOP_OK;
}
+static struct iz_cmd_event del_phy_response_event[] = {
+ {
+ .call = del_phy_response,
+ .nl = IEEE802154_ADD_IFACE,
+ },
+ { 0, 0 },
+};
+
const struct iz_module iz_phy = {
.name = "PHY 802.15.4",
.commands = {
@@ -286,10 +318,9 @@ const struct iz_module iz_phy = {
.usage = "[phy]",
.doc = "List phys(s).",
.nl_cmd = IEEE802154_LIST_PHY,
- .nl_resp = IEEE802154_LIST_PHY,
.parse = list_phy_parse,
.request = list_phy_request,
- .response = list_phy_response,
+ .response = list_phy_response_event,
.finish = list_phy_finish,
},
{
@@ -297,30 +328,27 @@ const struct iz_module iz_phy = {
.usage = "phy [name [hwaddr]]",
.doc = "Add an WPAN interface attached to specified phy.",
.nl_cmd = IEEE802154_ADD_IFACE,
- .nl_resp = IEEE802154_ADD_IFACE,
.parse = add_phy_parse,
.request = add_phy_request,
- .response = add_phy_response,
+ .response = add_phy_response_event,
},
{
.name = "monitor",
.usage = "phy [name]",
.doc = "Add monitoring interface, passing all received frames.",
.nl_cmd = IEEE802154_ADD_IFACE,
- .nl_resp = IEEE802154_ADD_IFACE,
.parse = monitor_phy_parse,
.request = monitor_phy_request,
- .response = monitor_phy_response,
+ .response = monitor_phy_response_event,
},
{
.name = "del",
.usage = "[phy] iface",
.doc = "Delete the specified interface.",
.nl_cmd = IEEE802154_DEL_IFACE,
- .nl_resp = IEEE802154_DEL_IFACE,
.parse = del_phy_parse,
.request = del_phy_request,
- .response = del_phy_response,
+ .response = del_phy_response_event,
},
{}}
};
diff --git a/src/iz.c b/src/iz.c
index 659a486..4750f6e 100644
--- a/src/iz.c
+++ b/src/iz.c
@@ -299,8 +299,14 @@ static int iz_cb_valid(struct nl_msg *msg, void *arg)
dprintf(1, "Received command %d (%d) for interface\n",
ghdr->cmd, ghdr->version);
- if (cmd->desc->listener || cmd->desc->nl_resp == ghdr->cmd) {
- iz_exit = cmd->desc->response(cmd, ghdr, attrs);
+ if (cmd->desc->response[0].nl == __IEEE802154_CMD_MAX)
+ iz_exit = cmd->desc->response->call(cmd, ghdr, attrs);
+ else {
+ int i;
+
+ for (i = 0; cmd->desc->response[i].nl; i++)
+ if (cmd->desc->response[i].nl == ghdr->cmd)
+ iz_exit = cmd->desc->response->call(cmd, ghdr, attrs);
}
return 0;
diff --git a/src/iz.h b/src/iz.h
index 7e9e717..679254d 100644
--- a/src/iz.h
+++ b/src/iz.h
@@ -37,14 +37,21 @@ typedef enum {
IZ_STOP_ERR,
} iz_res_t;
+/*
+ * iz command event
+ * FIXME: add event-style for all commands..
+ */
+struct iz_cmd_event {
+ iz_res_t (*call)();
+ int nl;
+};
+
/* iz command descriptor */
struct iz_cmd_desc {
const char *name; /* Name (as in command line) */
const char *usage; /* Arguments list */
const char *doc; /* One line command description */
unsigned char nl_cmd; /* NL command ID */
- unsigned char nl_resp; /* NL command response ID (optional) */
- unsigned listener : 1; /* Listen for all events */
/* Parse command line, fill in iz_cmd struct. */
/* You must set cmd->flags here! */
@@ -55,7 +62,7 @@ struct iz_cmd_desc {
iz_res_t (*request)(struct iz_cmd *cmd, struct nl_msg *msg);
/* Handle an incoming netlink message */
- iz_res_t (*response)(struct iz_cmd *cmd, struct genlmsghdr *ghdr, struct nlattr **attrs);
+ struct iz_cmd_event *response;
/* Handle the end of multipart message */
iz_res_t (*finish)(struct iz_cmd *cmd);
--
1.7.2.3
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Linux-zigbee-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel