]> git.ipfire.org Git - thirdparty/iw.git/blame - connect.c
remove netns stuff from nl80211.h -- not so soon
[thirdparty/iw.git] / connect.c
CommitLineData
99dde7aa
JB
1#include <errno.h>
2
3#include <netlink/genl/genl.h>
4#include <netlink/genl/family.h>
5#include <netlink/genl/ctrl.h>
6#include <netlink/msg.h>
7#include <netlink/attr.h>
8
9#include "nl80211.h"
10#include "iw.h"
11
12static int iw_connect(struct nl80211_state *state,
13 struct nl_cb *cb,
14 struct nl_msg *msg,
15 int argc, char **argv)
16{
17 char *end;
51e9bd80 18 unsigned char bssid[6];
99dde7aa
JB
19 int freq;
20
21 if (argc < 1)
22 return 1;
23
24 /* SSID */
25 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
26 argv++;
27 argc--;
28
29 /* freq */
30 if (argc) {
31 freq = strtoul(argv[0], &end, 10);
32 if (*end == '\0') {
33 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
34 argv++;
35 argc--;
36 }
37 }
38
39 /* bssid */
40 if (argc) {
51e9bd80
JB
41 if (mac_addr_a2n(bssid, argv[0]) == 0) {
42 NLA_PUT(msg, NL80211_ATTR_MAC, 6, bssid);
43 argv++;
44 argc--;
45 }
99dde7aa
JB
46 }
47
51e9bd80
JB
48 if (!argc)
49 return 0;
50
51 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
99dde7aa
JB
52 return 1;
53
51e9bd80
JB
54 argv++;
55 argc--;
56
57 return parse_keys(msg, argv, argc);
99dde7aa
JB
58 nla_put_failure:
59 return -ENOSPC;
60}
61
62static int disconnect(struct nl80211_state *state,
63 struct nl_cb *cb,
64 struct nl_msg *msg,
65 int argc, char **argv)
66{
67 return 0;
68}
69TOPLEVEL(disconnect, NULL,
70 NL80211_CMD_DISCONNECT, 0, CIB_NETDEV, disconnect,
71 "Disconnect from the current network.");
51e9bd80 72TOPLEVEL(connect, "<SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465]",
99dde7aa
JB
73 NL80211_CMD_CONNECT, 0, CIB_NETDEV, iw_connect,
74 "Join the network with the given SSID (and frequency, BSSID).");