xref: /plan9/sys/src/libauth/auth_wep.c (revision 39734e7ed1eb944f5e7b41936007d0d38b560d7f)
1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include "authlocal.h"
5 
6 /*
7  *  make factotum add wep keys to an 802.11 device
8  */
9 int
auth_wep(char * dev,char * fmt,...)10 auth_wep(char *dev, char *fmt, ...)
11 {
12 	AuthRpc *rpc;
13 	char *params, *p;
14 	int fd;
15 	va_list arg;
16 	int rv;
17 
18 	rv = -1;
19 
20 	if(dev == nil){
21 		werrstr("no device specified");
22 		return rv;
23 	}
24 
25 	fd = open("/mnt/factotum/rpc", ORDWR);
26 	if(fd < 0)
27 		return rv;
28 
29 	rpc = auth_allocrpc(fd);
30 	if(rpc != nil){
31 		quotefmtinstall();	/* just in case */
32 		va_start(arg, fmt);
33 		params = vsmprint(fmt, arg);
34 		va_end(arg);
35 		if(params != nil){
36 			p = smprint("proto=wep %s", params);
37 			if(p != nil){
38 				if(auth_rpc(rpc, "start", p, strlen(p)) == ARok
39 				&& auth_rpc(rpc, "write", dev, strlen(dev)) == ARok)
40 					rv = 0;
41 				free(p);
42 			}
43 			free(params);
44 		}
45 		auth_freerpc(rpc);
46 	}
47 	close(fd);
48 
49 	return rv;
50 }
51