X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=connect.c;h=56771249e234bc14bd5234a68b5565f08688eb14;hb=8b80a2b361e97e560a1300d693290b1d5a984316;hp=a37435c00505673dbe16b164a5284d2e10a87066;hpb=75f4204cd7d27caa080d64f6f5cf3c4b366c839f;p=thirdparty%2Fiw.git diff --git a/connect.c b/connect.c index a37435c..5677124 100644 --- a/connect.c +++ b/connect.c @@ -9,7 +9,7 @@ #include "nl80211.h" #include "iw.h" -static int iw_conn(struct nl80211_state *state, struct nl_cb *cb, +static int iw_conn(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv, enum id_input id) { @@ -59,7 +59,6 @@ static int iw_conn(struct nl80211_state *state, struct nl_cb *cb, } static int disconnect(struct nl80211_state *state, - struct nl_cb *cb, struct nl_msg *msg, int argc, char **argv, enum id_input id) @@ -70,7 +69,7 @@ TOPLEVEL(disconnect, NULL, NL80211_CMD_DISCONNECT, 0, CIB_NETDEV, disconnect, "Disconnect from the current network."); -static int iw_connect(struct nl80211_state *state, struct nl_cb *cb, +static int iw_connect(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv, enum id_input id) { @@ -94,15 +93,15 @@ static int iw_connect(struct nl80211_state *state, struct nl_cb *cb, argv++; } + err = __prepare_listen_events(state); + if (err) + return err; + conn_argc = 3 + argc; conn_argv = calloc(conn_argc, sizeof(*conn_argv)); if (!conn_argv) return -ENOMEM; - err = __prepare_listen_events(state); - if (err) - return err; - conn_argv[0] = dev; conn_argv[1] = "connect"; conn_argv[2] = "establish"; @@ -145,3 +144,74 @@ TOPLEVEL(connect, "[-w] [] [] [key 0:abcde d:1:616263 "Join the network with the given SSID (and frequency, BSSID).\n" "With -w, wait for the connect to finish or fail."); HIDDEN(connect, establish, "", NL80211_CMD_CONNECT, 0, CIB_NETDEV, iw_conn); + +static int iw_auth(struct nl80211_state *state, + struct nl_msg *msg, int argc, char **argv, + enum id_input id) +{ + char *end; + unsigned char bssid[6]; + int freq; + bool need_key = false; + + if (argc < 4) + return 1; + + /* SSID */ + NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]); + argv++; + argc--; + + /* bssid */ + if (mac_addr_a2n(bssid, argv[0]) == 0) { + NLA_PUT(msg, NL80211_ATTR_MAC, 6, bssid); + argv++; + argc--; + } else { + return 1; + } + + /* FIXME */ + if (strcmp(argv[0], "open") == 0) { + NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, + NL80211_AUTHTYPE_OPEN_SYSTEM); + } else if (strcmp(argv[0], "shared") == 0) { + NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, + NL80211_AUTHTYPE_SHARED_KEY); + need_key = true; + } else { + return 1; + } + argv++; + argc--; + + freq = strtoul(argv[0], &end, 10); + if (*end == '\0') { + NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); + argv++; + argc--; + } else { + return 1; + } + + if (!argc && need_key) + return 1; + if (argc && !need_key) + return 1; + if (!argc) + return 0; + + if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0) + return 1; + + argv++; + argc--; + + return parse_keys(msg, argv, argc); + nla_put_failure: + return -ENOSPC; +} + +TOPLEVEL(auth, " [key 0:abcde d:1:6162636465]", + NL80211_CMD_AUTHENTICATE, 0, CIB_NETDEV, iw_auth, + "Authenticate with the given network.\n");