OSDN Git Service

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