1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/* Note : this particular snipset of code is available under
* the LGPL, MPL or BSD license (at your choice).
* Jean II
*/
#define MAX_KEY_SIZE 16
#define MAX_KEYS 8
int key_on = 0;
int key_open = 1;
int key_current = 0;
char key_table[MAX_KEYS][MAX_KEY_SIZE];
int key_size[MAX_KEYS];
#if WIRELESS_EXT > 8
case SIOCSIWENCODE:
/* Basic checking... */
if(wrq->u.encoding.pointer != (caddr_t) 0)
{
int index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
/* Check the size of the key */
if(wrq->u.encoding.length > MAX_KEY_SIZE)
{
ret = -EINVAL;
break;
}
/* Check the index */
if((index < 0) || (index >= MAX_KEYS))
index = key_current;
/* Copy the key in the driver */
if(copy_from_user(key_table[index], wrq->u.encoding.pointer,
wrq->u.encoding.length))
{
key_size[index] = 0;
ret = -EFAULT;
break;
}
key_size[index] = wrq->u.encoding.length;
key_on = 1;
}
else
{
int index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
/* Do we want to just set the current key ? */
if((index >= 0) && (index < MAX_KEYS))
{
if(key_size[index] > 0)
{
key_current = index;
key_on = 1;
}
else
ret = -EINVAL;
}
}
/* Read the flags */
if(wrq->u.encoding.flags & IW_ENCODE_DISABLED)
key_on = 0; /* disable encryption */
if(wrq->u.encoding.flags & IW_ENCODE_RESTRICTED)
key_open = 0; /* disable open mode */
if(wrq->u.encoding.flags & IW_ENCODE_OPEN)
key_open = 1; /* enable open mode */
break;
case SIOCGIWENCODE:
/* only super-user can see encryption key */
if(!suser())
{
ret = -EPERM;
break;
}
/* Basic checking... */
if(wrq->u.encoding.pointer != (caddr_t) 0)
{
int index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
/* Set the flags */
wrq->u.encoding.flags = 0;
if(key_on == 0)
wrq->u.encoding.flags |= IW_ENCODE_DISABLED;
if(key_open == 0)
wrq->u.encoding.flags |= IW_ENCODE_RESTRICTED;
else
wrq->u.encoding.flags |= IW_ENCODE_OPEN;
/* Which key do we want */
if((index < 0) || (index >= MAX_KEYS))
index = key_current;
wrq->u.encoding.flags |= index + 1;
/* Copy the key to the user buffer */
wrq->u.encoding.length = key_size[index];
if(copy_to_user(wrq->u.encoding.pointer, key_table[index],
key_size[index]))
ret = -EFAULT;
}
break;
#endif /* WIRELESS_EXT > 8 */
#if WIRELESS_EXT > 8
range.encoding_size[0] = 8; /* DES = 64 bits key */
range.encoding_size[1] = 16;
range.num_encoding_sizes = 2;
range.max_encoding_tokens = 8;
#endif /* WIRELESS_EXT > 8 */
|