Root/ks7010/src/ks7010_config.c

1#include <linux/kernel.h>
2#include <linux/mmc/sdio_func.h>
3
4#include "ks_wlan.h"
5#include "ks_hostif.h"
6#include "ks_wlan_ioctl.h"
7#include "ks_debug.h"
8
9static int wep_on_off;
10#define WEP_OFF 0
11#define WEP_ON_64BIT 1
12#define WEP_ON_128BIT 2
13
14static int wep_type;
15#define WEP_KEY_CHARACTER 0
16#define WEP_KEY_HEX 1
17
18static
19void analyze_character_wep_key(struct ks_wlan_parameter *param, int wep_key_index, char *value)
20{
21    int i;
22    unsigned char wep_key[26], key_length;
23
24    key_length = (wep_on_off == WEP_ON_64BIT) ? 5 : 13;
25    /* 64bit key_length = 5; 128bit key_length = 13; */
26
27    for (i=0; i<key_length; i++) {
28        wep_key[i] = value[i];
29    }
30
31    if(wep_key_index < 0 || wep_key_index > 3)
32        return;
33
34    param->wep_key[wep_key_index].size = key_length;
35    for (i=0; i<(param->wep_key[wep_key_index].size); i++) {
36        param->wep_key[wep_key_index].val[i] = wep_key[i];
37    }
38}
39
40static
41void analyze_hex_wep_key(struct ks_wlan_parameter *param, int wep_key_index, char *value)
42{
43    unsigned char wep_end[26], i, j, key_length;
44
45    key_length = (wep_on_off == WEP_ON_64BIT) ? 10 : 26;
46    /* 64bit key_length = 10; 128bit key_length = 26; */
47
48    for (i=0; i<key_length; i++) {
49        wep_end[i] = value[i];
50        if (i % 2) {
51            /* Odd */
52            for (j=0x00; j<0x10; j++) {
53                if (j<0x0a) {
54                    if (wep_end[i] == j+0x30)
55                        wep_end[i] = j;
56                } else {
57                    if ((wep_end[i] == j+0x37) | (wep_end[i] == j+0x57))
58                        wep_end[i] = j;
59                }
60            }
61        } else {
62            /* Even */
63            for (j=0x00; j<0x10; j++) {
64                if (j<0x0a) {
65                    if (wep_end[i] == j+0x30) {
66                        wep_end[i] = j*16;
67                    }
68                } else {
69                    if ((wep_end[i] == j+0x37) | (wep_end[i] == j+0x57))
70                        wep_end[i] = j*16;
71                }
72            }
73        }
74    }
75
76    for (i=0; i<key_length/2; i++) {
77        wep_end[i] = wep_end[i*2] + wep_end[(i*2)+1];
78    }
79
80    if(wep_key_index < 0 || wep_key_index > 3)
81        return ;
82
83    param->wep_key[wep_key_index].size = key_length/2;
84    for (i=0; i<(param->wep_key[wep_key_index].size); i++) {
85        param->wep_key[wep_key_index].val[i] = wep_end[i];
86    }
87
88}
89
90static
91int rate_set_configuration(ks_wlan_private *priv, char *value)
92{
93    int rc=0;
94
95    priv->reg.tx_rate = TX_RATE_FIXED;
96    priv->reg.rate_set.size = 1;
97
98    switch(*value){
99    case '1': /* 1M 11M 12M 18M */
100        if(*(value+1) == '8'){
101            priv->reg.rate_set.body[0] = TX_RATE_18M;
102        }
103        else if(*(value+1) == '2'){
104            priv->reg.rate_set.body[0] = TX_RATE_12M|BASIC_RATE;
105        }
106        else if(*(value+1) == '1'){
107            priv->reg.rate_set.body[0] = TX_RATE_11M|BASIC_RATE;
108        }
109        else{
110            priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
111        }
112        break;
113    case '2': /* 2M 24M */
114        if(*(value+1) == '4'){
115            priv->reg.rate_set.body[0] = TX_RATE_24M|BASIC_RATE;
116        }
117        else{
118            priv->reg.rate_set.body[0] = TX_RATE_2M|BASIC_RATE;
119        }
120        break;
121    case '3': /* 36M */
122        priv->reg.rate_set.body[0] = TX_RATE_36M;
123        break;
124    case '4': /* 48M */
125        priv->reg.rate_set.body[0] = TX_RATE_48M;
126        break;
127    case '5': /* 5.5M 54M */
128        if(*(value+1) == '4'){
129            priv->reg.rate_set.body[0] = TX_RATE_54M;
130        }
131        else{
132            priv->reg.rate_set.body[0] = TX_RATE_5M|BASIC_RATE;
133        }
134        break;
135    case '6': /* 6M */
136        priv->reg.rate_set.body[0] = TX_RATE_6M|BASIC_RATE;
137        break;
138    case '9': /* 9M */
139        priv->reg.rate_set.body[0] = TX_RATE_9M;
140        break;
141    case 'K':
142        priv->reg.rate_set.body[6] = TX_RATE_36M;
143        priv->reg.rate_set.body[5] = TX_RATE_18M;
144        priv->reg.rate_set.body[4] = TX_RATE_24M|BASIC_RATE;
145        priv->reg.rate_set.body[3] = TX_RATE_12M|BASIC_RATE;
146        priv->reg.rate_set.body[2] = TX_RATE_6M|BASIC_RATE;
147        priv->reg.rate_set.body[1] = TX_RATE_11M|BASIC_RATE;
148        priv->reg.rate_set.body[0] = TX_RATE_2M|BASIC_RATE;
149        priv->reg.tx_rate = TX_RATE_FULL_AUTO;
150        priv->reg.rate_set.size = 7;
151        break;
152    default:
153        priv->reg.rate_set.body[11] = TX_RATE_54M;
154        priv->reg.rate_set.body[10] = TX_RATE_48M;
155        priv->reg.rate_set.body[9] = TX_RATE_36M;
156        priv->reg.rate_set.body[8] = TX_RATE_18M;
157        priv->reg.rate_set.body[7] = TX_RATE_9M;
158        priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
159        priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
160        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
161        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
162        priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
163        priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
164        priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
165        priv->reg.tx_rate = TX_RATE_FULL_AUTO;
166        priv->reg.rate_set.size = 12;
167        break;
168    }
169    return rc;
170}
171
172#ifndef NO_FIRMWARE_CLASS
173#include <linux/firmware.h>
174#else
175#define MAX_CONFIG_FILE_SIZE (1024*10)
176#endif
177int ks_wlan_read_config_file(ks_wlan_private *priv)
178{
179    struct {
180        const int key_len;
181        const char *key;
182        const char *val;
183    } cfg_tbl[] = {
184        {15,"BeaconLostCount", "20"}, /* 0 */
185        {7,"Channel", "1"}, /* 1 */
186        {17,"FragmentThreshold","2346"}, /* 2 */
187        {13,"OperationMode","Infrastructure"}, /* 3 */
188        {19,"PowerManagementMode","ACTIVE"}, /* 4 */
189        {12,"RTSThreshold","2347"}, /* 5 */
190        {4,"SSID","default"}, /* 6 */
191        {6,"TxRate","Auto"}, /* 7 */
192        {23,"AuthenticationAlgorithm",""}, /* 8 */
193        {12,"WepKeyValue1",""}, /* 9 */
194        {12,"WepKeyValue2",""}, /* 10 */
195        {12,"WepKeyValue3",""}, /* 11 */
196        {12,"WepKeyValue4",""}, /* 12 */
197        {8,"WepIndex","1"}, /* 13 */
198        {7,"WepType","STRING"}, /* 14 */
199        {3,"Wep","OFF"}, /* 15 */
200        {13,"PREAMBLE_TYPE","SHORT"}, /* 16 */
201        {8,"ScanType","ACTIVE_SCAN"}, /* 17 */
202        {8,"ROM_FILE", ROM_FILE}, /* 18 */
203        {7,"PhyType", "BG_MODE"}, /* 19 */
204        {7,"CtsMode", "FALSE"}, /* 20 */
205        {19,"PhyInformationTimer", "0"}, /* 21 */
206        {0,"",""},
207    };
208
209#ifndef NO_FIRMWARE_CLASS
210    const struct firmware *fw_entry;
211    struct device *dev = NULL;
212    int retval;
213#else
214    struct file *srcf;
215    int nr_read ;
216    int retval;
217    char *cfg_buf=NULL;
218    int orgfsuid, orgfsgid;
219    mm_segment_t orgfs;
220#endif
221    char cfg_file[]=CFG_FILE;
222    char *cur_p, *end_p;
223    char wk_buff[256], *wk_p;
224
225    /* Initialize Variable */
226    priv->reg.operation_mode = MODE_INFRASTRUCTURE; /* Infrastructure */
227    priv->reg.channel = 10; /* 10 */
228    memset(priv->reg.bssid, 0x0, ETH_ALEN); /* BSSID */
229    priv->reg.ssid.body[0] = '\0'; /* SSID */
230    priv->reg.ssid.size = 0; /* SSID size */
231    priv->reg.tx_rate = TX_RATE_AUTO; /* TxRate Fully Auto */
232    priv->reg.preamble = SHORT_PREAMBLE; /* Preamble = SHORT */
233    priv->reg.powermgt = POWMGT_ACTIVE_MODE; /* POWMGT_ACTIVE_MODE */
234    priv->reg.scan_type = ACTIVE_SCAN; /* Active */
235    priv->reg.beacon_lost_count = 20; /* Beacon Lost Count */
236    priv->reg.rts = 2347UL; /* RTS Threashold */
237    priv->reg.fragment = 2346UL; /* Fragmentation Threashold */
238
239    strcpy(&priv->reg.rom_file[0], ROM_FILE);
240
241    priv->skb = NULL;
242
243    priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; /* AuthenticationAlgorithm */
244
245    priv->reg.privacy_invoked = 0x00; /* WEP */
246    priv->reg.wep_index=0;
247    memset(&priv->reg.wep_key[0],0,sizeof(priv->reg.wep_key[0]));
248    memset(&priv->reg.wep_key[1],0,sizeof(priv->reg.wep_key[0]));
249    memset(&priv->reg.wep_key[2],0,sizeof(priv->reg.wep_key[0]));
250    memset(&priv->reg.wep_key[3],0,sizeof(priv->reg.wep_key[0]));
251
252    priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
253    priv->reg.cts_mode = CTS_MODE_FALSE;
254    priv->reg.phy_info_timer = 0;
255    priv->reg.rate_set.body[11] = TX_RATE_54M;
256    priv->reg.rate_set.body[10] = TX_RATE_48M;
257    priv->reg.rate_set.body[9] = TX_RATE_36M;
258    priv->reg.rate_set.body[8] = TX_RATE_18M;
259    priv->reg.rate_set.body[7] = TX_RATE_9M;
260    priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
261    priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
262    priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
263    priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
264    priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
265    priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
266    priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
267    priv->reg.tx_rate = TX_RATE_FULL_AUTO;
268    priv->reg.rate_set.size = 12;
269
270#ifndef NO_FIRMWARE_CLASS
271#if (defined _PCMCIA_)
272    dev = &priv->ks_wlan_hw.pcmcia_dev->dev;
273#elif (defined _PCI_)
274    dev = &priv->ks_wlan_hw.pci_dev->dev;
275#elif (defined _SDIO_)
276    dev = &priv->ks_wlan_hw.sdio_card->func->dev;
277#endif
278    if((retval = request_firmware(&fw_entry, cfg_file, dev)) !=0 ){
279        DPRINTK(1, "error request_firmware() file=%s ret=%d\n", cfg_file, retval);
280        return 1;
281    }
282
283    DPRINTK(4, "success request_firmware() file=%s size=%d\n", cfg_file, fw_entry->size);
284    cur_p = fw_entry->data;
285    end_p = cur_p + fw_entry->size;
286#else
287    orgfsuid=current->fsuid;
288    orgfsgid=current->fsgid;
289    orgfs=get_fs();
290    set_fs(KERNEL_DS);
291
292    srcf = filp_open(cfg_file, O_RDONLY, 0);
293    if (IS_ERR(srcf)) {
294        printk(KERN_ERR "error %ld opening %s\n", -PTR_ERR(srcf),cfg_file);
295        goto no_config_file;
296    }
297
298        if (!(srcf->f_op && srcf->f_op->read)) {
299                printk(KERN_ERR "%s does not have a read method\n", cfg_file);
300        goto no_config_file;
301        }
302
303    cfg_buf = (char *)kzalloc(MAX_CONFIG_FILE_SIZE, GFP_ATOMIC);
304        if (!cfg_buf) {
305                printk(KERN_ERR "%s does not read : out of memory \n", cfg_file);
306        goto no_config_file;
307        }
308
309        nr_read = srcf->f_op->read(srcf, (unsigned char *)cfg_buf, MAX_CONFIG_FILE_SIZE, &srcf->f_pos);
310
311    DPRINTK(1, "read retval=%d file=%s\n", nr_read, priv->reg.cfg_file);
312    retval=filp_close(srcf ,NULL);
313    if (retval)
314        DPRINTK(1, "error %d closing %s\n", -retval,priv->reg.cfg_file);
315
316        if (nr_read < 1) {
317                printk(KERN_ERR "%s does not read : file is empty num=%d\n", cfg_file, nr_read);
318        goto no_config_file;
319        }else if(nr_read > MAX_CONFIG_FILE_SIZE){
320                printk(KERN_ERR "%s does not read : file is too big \n", cfg_file);
321        goto no_config_file;
322    }
323    cur_p = cfg_buf;
324    end_p = cur_p + nr_read;
325#endif
326    *end_p = '\0';
327
328    while (cur_p < end_p) {
329        int i, j, len;
330
331        len = end_p - cur_p;
332        for (i=0; cfg_tbl[i].key_len != 0; i++) {
333            if (*cur_p == '#') {
334                break;
335            }
336            if (len < cfg_tbl[i].key_len) {
337                continue;
338            }
339            if (!strncmp(cfg_tbl[i].key, cur_p, cfg_tbl[i].key_len)) {
340                break;
341            }
342        }
343        if ((*cur_p == '#') || (cfg_tbl[i].key_len == 0)) {
344            while (*cur_p != '\n') {
345                if (cur_p >= end_p) {
346                    break;
347                }
348                cur_p++;
349            }
350            cur_p++;
351        } else {
352            cur_p += cfg_tbl[i].key_len;
353            if (*cur_p != '=') {
354                while (*cur_p != '\n') {
355                    if (cur_p >= end_p) {
356                        break;
357                    }
358                    cur_p++;
359                }
360                continue;
361            }
362            cur_p++;
363
364            for (j=0,wk_p=cur_p; *wk_p != '\n' && wk_p < end_p; j++,wk_p++) {
365                wk_buff[j] = *wk_p;
366            }
367            wk_buff[j] = '\0';
368            cur_p = wk_p;
369            DPRINTK(4,"%s=%s\n",cfg_tbl[i].key, wk_buff);
370            wk_p = wk_buff;
371
372            switch (i) {
373            case 0: /* "BeaconLostCount", "10" */
374                priv->reg.beacon_lost_count = simple_strtol(wk_buff, NULL, 10);
375                break;
376            case 1: /* "Channel", "1" */
377                priv->reg.channel = simple_strtol(wk_buff, NULL, 10);
378                break;
379            case 2: /* "FragmentThreshold","2346" */
380                j = simple_strtol(wk_buff, NULL, 10);
381                priv->reg.fragment = (unsigned long)j;
382                break;
383            case 3: /* "OperationMode","Infrastructure" */
384                switch (*wk_buff) {
385                case 'P':
386                    priv->reg.operation_mode = MODE_PSEUDO_ADHOC;
387                    break;
388                case 'I':
389                    priv->reg.operation_mode = MODE_INFRASTRUCTURE;
390                    break;
391                case '8':
392                    priv->reg.operation_mode = MODE_ADHOC;
393                    break;
394                default:
395                    priv->reg.operation_mode = MODE_INFRASTRUCTURE;
396                }
397                break;
398            case 4: /* "PowerManagementMode","POWER_ACTIVE" */
399                if (!strncmp(wk_buff, "SAVE1", 5)) {
400                    priv->reg.powermgt = POWMGT_SAVE1_MODE;
401                } else if (!strncmp(wk_buff, "SAVE2", 5)){
402                    priv->reg.powermgt = POWMGT_SAVE2_MODE;
403                } else {
404                    priv->reg.powermgt = POWMGT_ACTIVE_MODE;
405                }
406                break;
407            case 5: /* "RTSThreshold","2347" */
408                j = simple_strtol(wk_buff, NULL, 10);
409                priv->reg.rts = (unsigned long)j;
410                break;
411            case 6: /* "SSID","" */
412                if (*wk_p != '"')
413                    break;
414                wk_p++;
415                for (j=0; *wk_p != '"'; j++) {
416                    if (wk_p == '\0') {
417                        break;
418                    }
419                    priv->reg.ssid.body[j] = *wk_p++;
420                }
421                priv->reg.ssid.body[j] = '\0';
422                priv->reg.ssid.size = j;
423                wk_p++;
424                break;
425            case 7: /* "TxRate","Auto" */
426                rate_set_configuration(priv, wk_p);
427                break;
428            case 8: /* "AuthenticationAlgorithm","OPEN_SYSTEM" */
429                switch (*wk_p) {
430                case 'O': /* Authenticate System : Open System */
431                    priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
432                    break;
433                case 'S': /* Authenticate System : Shared Key */
434                    priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
435                    break;
436                }
437                break;
438            case 9: /* "WepKeyValue1","" */
439            case 10: /* "WepKeyValue2","" */
440            case 11: /* "WepKeyValue3","" */
441            case 12: /* "WepKeyValue4","" */
442                if (wep_on_off != WEP_OFF) {
443                    switch (wep_type) {
444                    case WEP_KEY_CHARACTER:
445                        analyze_character_wep_key(&priv->reg, (i-9), wk_p);
446                        break;
447                    case WEP_KEY_HEX:
448                        analyze_hex_wep_key(&priv->reg, (i-9), wk_p);
449                        break;
450                    }
451                }
452                break;
453            case 13: /* "WepIndex","1"->0 (So, Zero Origin) */
454                priv->reg.wep_index = simple_strtol(wk_buff, NULL, 10) - 1;
455                break;
456            case 14: /* "WepType","STRING" */
457                if (!strncmp(wk_buff, "STRING", 6)) {
458                    wep_type = WEP_KEY_CHARACTER;
459                } else {
460                    wep_type = WEP_KEY_HEX;
461                }
462                break;
463            case 15: /* "Wep","OFF" */
464                if (!strncmp(wk_buff, "OFF", 3)) {
465                    priv->reg.privacy_invoked = 0x00;
466                    wep_on_off = WEP_OFF;
467                } else { /* 64bit or 128bit */
468                    priv->reg.privacy_invoked = 0x01;
469                    if (*wk_buff == '6') { /* 64bit */
470                        wep_on_off = WEP_ON_64BIT;
471                    } else { /* 128bit */
472                        wep_on_off = WEP_ON_128BIT;
473                    }
474                }
475                break;
476            case 16: /* "PREAMBLE_TYPE","LONG" */
477                if (!strncmp(wk_buff, "SHORT", 5)) {
478                    priv->reg.preamble = SHORT_PREAMBLE;
479                } else { /* "LONG" */
480                    priv->reg.preamble = LONG_PREAMBLE;
481                }
482                break;
483            case 17: /* "ScanType","ACTIVE_SCAN" */
484                if (!strncmp(wk_buff, "PASSIVE_SCAN", 12)) {
485                    priv->reg.scan_type = PASSIVE_SCAN;
486                } else { /* "ACTIVE_SCAN" */
487                    priv->reg.scan_type = ACTIVE_SCAN;
488                }
489                break;
490            case 18: // "ROM_FILE",ROMFILE
491                if (*wk_p != '"')
492                    break;
493                wk_p++;
494                for (j=0; *wk_p != '"'; j++) {
495                    if (wk_p == '\0') {
496                        break;
497                    }
498                    priv->reg.rom_file[j] = *wk_p++;
499                }
500                priv->reg.rom_file[j] = '\0';
501                wk_p++;
502                break;
503            case 19: /*"PhyType", "BG_MODE" */
504                if (!strncmp(wk_buff, "B_MODE", 6)) {
505                    priv->reg.phy_type = D_11B_ONLY_MODE;
506                } else if (!strncmp(wk_buff, "G_MODE", 6)) {
507                    priv->reg.phy_type = D_11G_ONLY_MODE;
508                } else {
509                    priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
510                }
511                break;
512            case 20: /* "CtsMode", "FALSE" */
513                if (!strncmp(wk_buff, "TRUE", 4)) {
514                    priv->reg.cts_mode = CTS_MODE_TRUE;
515                } else {
516                    priv->reg.cts_mode = CTS_MODE_FALSE;
517                }
518                break;
519            case 21: /* "PhyInformationTimer", "0" */
520                j = simple_strtol(wk_buff, NULL, 10);
521                priv->reg.phy_info_timer = (uint16_t)j;
522                break;
523            default:
524                break;
525            }
526            if (cur_p >= end_p) {
527                break;
528            }
529            cur_p++;
530        }
531
532    }
533#ifndef NO_FIRMWARE_CLASS
534    release_firmware(fw_entry);
535#else
536no_config_file:
537    kfree(cfg_buf);
538    set_fs(orgfs);
539    current->fsuid=orgfsuid;
540    current->fsgid=orgfsgid;
541#endif
542
543    DPRINTK(3,"\n operation_mode = %d\n channel = %d\n ssid = %s\n tx_rate = %d\n \
544   preamble = %d\n powermgt = %d\n scan_type = %d\n beacon_lost_count = %d\n rts = %d\n \
545   fragment = %d\n privacy_invoked = %d\n wep_type = %d\n wep_on_off = %d\n wep_index = %d\n romfile = %s\n",
546        priv->reg.operation_mode,priv->reg.channel,&priv->reg.ssid.body[0],priv->reg.tx_rate,
547        priv->reg.preamble,priv->reg.powermgt,priv->reg.scan_type,priv->reg.beacon_lost_count,
548        priv->reg.rts,priv->reg.fragment,priv->reg.privacy_invoked,wep_type,wep_on_off,priv->reg.wep_index,
549        &priv->reg.rom_file[0]
550        );
551    DPRINTK(3,"\n phy_type = %d\n cts_mode = %d\n tx_rate = %d\n phy_info_timer = %d\n",
552        priv->reg.phy_type,priv->reg.cts_mode,priv->reg.tx_rate,priv->reg.phy_info_timer );
553
554    return(0);
555}
556
557

Archive Download this file



interactive