From 3e81b0123b4bbfedbdc1135a6a4305c347f91a3a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Aug 2003 16:41:59 +0000 Subject: Initial commit git-svn-id: file:///home/lennart/svn/public/aeswepd/trunk@3 022f378f-78c4-0310-b860-d162c87e6274 --- src/iwkey.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/iwkey.c (limited to 'src/iwkey.c') 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 +#include +#include +#include +#include + +#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; +} -- cgit