diff --git a/interface.c b/interface.c index efc2d93..57ba65f 100644 --- a/interface.c +++ b/interface.c @@ -45,6 +45,10 @@ static int get_if_type(int *argc, char ***argv, enum nl80211_iftype *type) } else if (strcmp(tpstr, "station") == 0) { *type = NL80211_IFTYPE_STATION; return 1; + } else if (strcmp(tpstr, "mp") == 0 || + strcmp(tpstr, "mesh") == 0 ) { + *type = NL80211_IFTYPE_MESH_POINT; + return 1; } @@ -109,6 +113,53 @@ static int handle_interface_add(struct nl80211_state *state, return 0; } +static int handle_interface_mesh_cfg(struct nl80211_state *state, + char *phy, char *dev, int argc, char **argv) +{ + char *mesh_id; + int err; + struct nl_msg *msg; + + if (argc < 1) { + fprintf(stderr, "not enough arguments\n"); + return -1; + } + + mesh_id = argv[0]; + argc--; + argv++; + + if (argc) { + fprintf(stderr, "too many arguments\n"); + return -1; + } + + msg = nlmsg_alloc(); + if (!msg) { + fprintf(stderr, "failed to allocate netlink msg\n"); + return -1; + } + + genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0, + 0, NL80211_CMD_SET_MESH_CFG, 0); + if (dev) + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(dev)); + if (phy) + return -1; /* XXX TODO */ + NLA_PUT_STRING(msg, NL80211_ATTR_MESH_ID, mesh_id); + + if ((err = nl_send_auto_complete(state->nl_handle, msg)) < 0 || + (err = nl_wait_for_ack(state->nl_handle)) < 0) { + nla_put_failure: + fprintf(stderr, "failed to set mesh configuration: %d\n", err); + nlmsg_free(msg); + return -1; + } + + nlmsg_free(msg); + + return 0; +} static int handle_interface_del(struct nl80211_state *state, char *phy, char *dev, int argc, char **argv) { @@ -163,6 +214,8 @@ int handle_interface(struct nl80211_state *state, return handle_interface_add(state, phy, dev, argc, argv); else if (strcmp(cmd, "del") == 0) return handle_interface_del(state, phy, dev, argc, argv); + else if (strcmp(cmd, "mesh_cfg") == 0) + return handle_interface_mesh_cfg(state, phy, dev, argc, argv); printf("invalid interface command %s\n", cmd); return -1; diff --git a/iw.c b/iw.c index bff5f4b..bc19562 100644 --- a/iw.c +++ b/iw.c @@ -96,7 +96,8 @@ void usage(char *argv0) "where COMMAND := { add | del }\n" "\n" "For add, OPTIONS := type \n" - "For del, OPTIONS should be blank and phydev is the interface to delete.\n", argv0); + "For del, OPTIONS should be blank and phydev is the interface to delete.\n" + "For mesh_cfg, phydev is the mesh device and OPTIONS := \n", argv0); } int main(int argc, char **argv)