This allows setting up a network without a PAN
 coordinator. Necessary if you want to be compatible
 with the contiki implementation.

Signed-off-by: Stefan Schmidt <ste...@datenfreihafen.org>
---
 src/iz-mac.c |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/src/iz-mac.c b/src/iz-mac.c
index 7c1e616..be980d6 100644
--- a/src/iz-mac.c
+++ b/src/iz-mac.c
@@ -253,6 +253,88 @@ static struct iz_cmd_event list_response_event[] = {
        {},
 };
 
+/******************/
+/* SET handling  */
+/******************/
+
+static iz_res_t set_parse(struct iz_cmd *cmd)
+{
+       cmd->flags = NLM_F_REQUEST;
+       return IZ_CONT_OK;
+}
+
+static iz_res_t set_request(struct iz_cmd *cmd, struct nl_msg *msg)
+{
+       char *dummy;
+       uint16_t pan_id, short_addr;
+       uint8_t chan;
+
+       if (!cmd->argv[1])
+               return IZ_STOP_ERR;
+       NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, cmd->argv[1]);
+
+       if (!cmd->argv[2])
+               return IZ_STOP_ERR;
+       pan_id = strtol(cmd->argv[2], &dummy, 16);
+       if (*dummy) {
+               printf("Bad PAN ID!\n");
+               return IZ_STOP_ERR;
+       }
+       NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, pan_id);
+
+       if (!cmd->argv[3])
+               return IZ_STOP_ERR;
+       short_addr = strtol(cmd->argv[3], &dummy, 16);
+       if (*dummy) {
+               printf("Bad short address!\n");
+               return IZ_STOP_ERR;
+       }
+       NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, short_addr);
+
+       if (!cmd->argv[4])
+               return IZ_STOP_ERR;
+       chan = strtol(cmd->argv[4], &dummy, 10);
+       if (*dummy) {
+               printf("Bad channel number!\n");
+               return IZ_STOP_ERR;
+       }
+       NLA_PUT_U8(msg, IEEE802154_ATTR_CHANNEL, chan);
+
+       /* set all unneeded attributes to 0*/
+       NLA_PUT_U8(msg, IEEE802154_ATTR_PAN_COORD, 0);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_BCN_ORD, 0);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_SF_ORD, 0);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_BAT_EXT, 0);
+       NLA_PUT_U8(msg, IEEE802154_ATTR_COORD_REALIGN, 0);
+
+       return IZ_CONT_OK;
+
+nla_put_failure:
+       return IZ_STOP_ERR;
+}
+
+static iz_res_t set_response(struct iz_cmd *cmd, struct genlmsghdr *ghdr, 
struct nlattr **attrs)
+{
+       if (!attrs[IEEE802154_ATTR_SHORT_ADDR] ||
+               !attrs[IEEE802154_ATTR_STATUS] )
+               return IZ_STOP_ERR;
+
+       printf("Set PAN ID %04hx, short address %04hx, status %i\n",
+               nla_get_u16(attrs[IEEE802154_ATTR_COORD_PAN_ID]),
+               nla_get_u16(attrs[IEEE802154_ATTR_SHORT_ADDR]),
+               nla_get_u8(attrs[IEEE802154_ATTR_CHANNEL]));
+
+       return IZ_STOP_OK;
+}
+
+static struct iz_cmd_event set_response_event[] = {
+       {
+               .call = set_response,
+               .nl = IEEE802154_START_CONF,
+       },
+       {},
+};
+
 /************************/
 /* ASSOCIATE handling   */
 /************************/
@@ -473,6 +555,15 @@ const struct iz_module iz_mac = {
                .response       = list_response_event,
                .finish         = list_finish,
        },
+       {
+               .name           = "set",
+               .usage          = "<iface> <pan> <addr> <channel>",
+               .doc            = "Set address, channel and pan for an 
interface.",
+               .nl_cmd         = IEEE802154_START_REQ,
+               .parse          = set_parse,
+               .request        = set_request,
+               .response       = set_response_event,
+       },
        {}}
 };
 
-- 
1.7.9.6 (Apple Git-31.1)
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to