summaryrefslogtreecommitdiffstats
path: root/src/iwkey.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-08-09 16:41:59 +0000
committerLennart Poettering <lennart@poettering.net>2003-08-09 16:41:59 +0000
commit3e81b0123b4bbfedbdc1135a6a4305c347f91a3a (patch)
tree0df13d3199a04b9ac8b3c576d9f4881593a87a36 /src/iwkey.c
parentba2dc48008777865fec281837ad9869d76cf8e87 (diff)
Initial commit
git-svn-id: file:///home/lennart/svn/public/aeswepd/trunk@3 022f378f-78c4-0310-b860-d162c87e6274
Diffstat (limited to 'src/iwkey.c')
-rw-r--r--src/iwkey.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/iwkey.c b/src/iwkey.c
new file mode 100644
index 0000000..3875594
--- /dev/null
+++ b/src/iwkey.c
@@ -0,0 +1,87 @@
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "iwkey.h"
+#include "wireless.h"
+#include "util.h"
+
+static int n_used_keys = 0;
+
+int wep_key_add(struct interface *i, uint8_t w[WEP_KEY_LEN]) {
+ struct iwreq req;
+ assert(i);
+
+ if (n_used_keys >= n_max_keys) {
+ fprintf(stderr, "Too many keys added!\n");
+ return -1;
+ }
+
+ memset(&req, 0, sizeof(req));
+ strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
+
+ req.u.encoding.pointer = w;
+ req.u.encoding.length = WEP_KEY_LEN;
+ req.u.encoding.flags = key_map[n_used_keys++]+1;
+
+ if (ioctl(i->fd, SIOCSIWENCODE, &req) < 0) {
+ fprintf(stderr, "ioctl(SIOCSIWENCODE): %s\n", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+int wep_key_finish(struct interface *i) {
+ struct iwreq req;
+ assert(i);
+
+ if (n_used_keys) {
+ uint8_t tmp[WEP_KEY_LEN];
+ int j;
+
+ memset(&req, 0, sizeof(req));
+ strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
+
+ req.u.encoding.pointer = tmp;
+ req.u.encoding.length = WEP_KEY_LEN;
+ req.u.encoding.flags = (key_map[n_used_keys-1]+1);
+
+ if (ioctl(i->fd, SIOCGIWENCODE, &req) < 0) {
+ fprintf(stderr, "ioctl(SIOCGIWENCODE): %s\n", strerror(errno));
+ return -1;
+ }
+
+ for (j = n_used_keys; j < n_max_keys; j++) {
+ memset(&req, 0, sizeof(req));
+ strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
+
+ req.u.encoding.pointer = tmp;
+ req.u.encoding.length = WEP_KEY_LEN;
+ req.u.encoding.flags = (key_map[j]+1);
+
+ if (ioctl(i->fd, SIOCSIWENCODE, &req) < 0) {
+ fprintf(stderr, "ioctl(SIOCSIWENCODE): %s\n", strerror(errno));
+ return -1;
+ }
+ }
+ }
+
+ memset(&req, 0, sizeof(req));
+ strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
+
+ req.u.encoding.pointer = NULL;
+ req.u.encoding.length = 0;
+ req.u.encoding.flags = IW_ENCODE_RESTRICTED;
+
+ if (ioctl(i->fd, SIOCSIWENCODE, &req) < 0) {
+ fprintf(stderr, "ioctl(SIOCSIWENCODE): %s\n", strerror(errno));
+ return -1;
+ }
+
+ n_used_keys = 0;
+
+ return 0;
+}