📄 sets.c
字号:
return 0;}int WepDlg(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ ENCRYPTION_INFO TempInfo; int d, wep_utruth = 0; wep_reverse = 1; wep_win = create_newwin(WINHEIGHT, WIDTH, 6, 0); keypad(wep_win, TRUE); refresh(); print_wep_menu(wep_win, wep_reverse); memcpy(&TempInfo, pEncryptionInfo, sizeof(ENCRYPTION_INFO)); while(1) { d = wgetch(wep_win); wep_utruth=0; switch(d) { case KEY_UP: if(wep_reverse == 1) wep_reverse = wep_config_choices; else --wep_reverse; break; case KEY_DOWN: if(wep_reverse == wep_config_choices) wep_reverse = 1; else ++wep_reverse; break; case 10: wep_epilogh = wep_reverse; wep_utruth=1; break; default: refresh(); break; } print_wep_menu(wep_win, wep_reverse); if(d == KEY_F(1)) /* User did a choice come out of the infinite loop */ { wclear(wep_win); destroy_win(wep_win); break; } if(wep_utruth==1){ if(wep_epilogh == 5) /* User did a choice come out of the infinite loop */ { wclear(wep_win); destroy_win(wep_win); wep_utruth = 0; break; } switch(wep_epilogh) { case 1: Set_Enc_Wep(pAppInfo, cname, fd, &TempInfo); refresh(); break; case 2: Set_WepKeyToUse(pAppInfo, cname, fd, &TempInfo); refresh(); break; case 3: Set_Wep_Value(pAppInfo, cname, fd, &TempInfo); refresh(); break;/* case 3: Set_Wep_Mode(pAppInfo, cname, fd, pEncryptionInfo); refresh(); break;*/ case 4: // Commits the changes, too memcpy(pEncryptionInfo, &TempInfo, sizeof(ENCRYPTION_INFO)); Set_Auth_Wep(pAppInfo, cname, fd, pEncryptionInfo); refresh(); break; default: refresh(); break; } wep_utruth = 0; } } //end while(1) return 0;}//************************* !proth***********************************int Set_Enc_Wep(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ WINDOW *enc_wep_win; key_strikes keystr; int value; enc_wep_win = create_inputwin(6, 60,15, 4); CancelExit(enc_wep_win, 1, 30); mvwprintw(enc_wep_win, 1,1, "Enabling Wep Key."); mvwprintw(enc_wep_win, 2,1, "(0) No Encryption, (1) 64 bit, (2) 128 bit."); mvwprintw(enc_wep_win,3, 1, "Select Encryption level : "); DECL_KEYSTR(enc_wep_win, wep_win, 1, 3, 27) if (KbdPrompt(&keystr) < 0) return 0; value = keystr.int_val; if((value < 0 )||(value > 2)){ ErrorWin("Invalid Encryption Level!!!"); return -EINVAL; } else { pEncryptionInfo->EncryptionLevel=value;#ifdef ATMEL_WLAN switch(pEncryptionInfo->EncryptionLevel) { case 0 : pEncryptionInfo->KeyLength =0; pEncryptionInfo->PairwiseCipherSuite = CIPHER_SUITE_NONE; break; case 1 : pEncryptionInfo->KeyLength =5; pEncryptionInfo->PairwiseCipherSuite = CIPHER_SUITE_WEP_64; break; case 2 : pEncryptionInfo->KeyLength =13; pEncryptionInfo->PairwiseCipherSuite = CIPHER_SUITE_WEP_128; break; }#endif wclear(enc_wep_win); destroy_win(enc_wep_win); redrawwin(wep_win); } return 0;}//*****************************!!!telos proths******************************int Set_WepKeyToUse(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ WINDOW *wep_value_win; struct iwreq wrq; key_strikes keystr; UCHAR W_KEY[LONG_WEP_KEY_SIZE]; int value; wep_value_win = create_inputwin(6, 60,15, 4); if (pEncryptionInfo->EncryptionLevel==0) { ErrorWin("Wep Key is Disabled. Enable it first"); return -EINVAL; } wattron(wep_value_win, A_BOLD); CancelExit(wep_value_win, 1,1); mvwprintw(wep_value_win, 2, 1, "Wep Key to use (1, 2, 3 or 4 ): "); DECL_KEYSTR(wep_value_win, wep_win, 1, 2, 33) if (KbdPrompt(&keystr) < 0) return 0; value = keystr.int_val; if ((value<1)||(value>4)) { ErrorWin("Invalid Wep Key!!!"); return -EINVAL; } pEncryptionInfo->WepKeyToUse= value-1;#ifdef ATMEL_WLAN pEncryptionInfo->KeyIndex= value;#endif strcpy(wrq.ifr_name,cname); W_KEY[0]=pEncryptionInfo->EncryptionLevel; wattroff(wep_value_win, A_BOLD); wrefresh(wep_value_win); return 0;} //*****************************!!!Deyterh*****************************int Set_Wep_Value(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ WINDOW *wep_value_win; key_strikes keystr; UCHAR W_KEY[LONG_WEP_KEY_SIZE]; int k, value; wep_value_win = create_inputwin(6, 60,15, 4); if (pEncryptionInfo->EncryptionLevel==0){ ErrorWin("Wep Key is Disabled. Enable it first"); return -EINVAL; } wattron(wep_value_win, A_BOLD); CancelExit(wep_value_win, 1, 1); k = pEncryptionInfo->WepKeyToUse; mvwprintw(wep_value_win, 2, 1, "Wep Key to Edit ( 1%s, 2%s, 3%s or 4%s ): ", k==0 ? "[TK]" : "", k==1 ? "[TK]" : "", k==2 ? "[TK]" : "", k==3 ? "[TK]" : "" ); DECL_KEYSTR(wep_value_win, wep_win, 1, 2, 39) if (KbdPrompt(&keystr) < 0) return 0; value = strlen(keystr.str_val) > 0 ? keystr.int_val: k+1; if ((value<1)||(value>4)) { ErrorWin("Invalid Wep Key!!!"); return -EINVAL; } W_KEY[0]=pEncryptionInfo->EncryptionLevel; if(WEP_KEY_CONV(value, W_KEY)!=0){ ErrorWin("Invalid Wep Key!!!"); return -EINVAL; }#ifndef ATMEL_WLAN switch(value-1) { case 0: memcpy(pEncryptionInfo->WepKey1,W_KEY,LONG_WEP_KEY_SIZE); break; case 1: memcpy(pEncryptionInfo->WepKey2,W_KEY,LONG_WEP_KEY_SIZE); break; case 2: memcpy(pEncryptionInfo->WepKey3,W_KEY,LONG_WEP_KEY_SIZE); break; case 3: memcpy(pEncryptionInfo->WepKey4,W_KEY,LONG_WEP_KEY_SIZE); break; }#else memcpy(pEncryptionInfo->KeyMaterial[value-1],W_KEY,LONG_WEP_KEY_SIZE); pEncryptionInfo->KeyMaterial[value-1][39] = 1;#endif // ATMEL_WLAN return 0;} //*****************************************!!!telos deyterhs**********************//*****************************************!!!trith**********************int Set_Wep_Mode(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ WINDOW *wep_mode_win; key_strikes keystr; int value; wep_mode_win = create_inputwin(6, 60,15, 4); wattron(wep_mode_win, A_BOLD); CancelExit(wep_mode_win, 1,1); mvwprintw(wep_mode_win, 2,1, "Wep Mode (0 for Optional 1 for Mandatory): "); DECL_KEYSTR(wep_mode_win, wep_win, 1, 2, 44) if (KbdPrompt(&keystr) < 0) return 0; value = keystr.int_val; if((value<0)||(value>1)) { ErrorWin("Invalid Wep Mode!!!"); return -EINVAL; } pEncryptionInfo->WepMode= value; return 0;}//*****************************************!!!telos triths**********************//*****************************************!!!tetarths**********************int Set_Auth_Wep(PDEVICE_CONFIGURATION pAppInfo, char *cname, int fd, PENCRYPTION_INFO pEncryptionInfo){ WINDOW *wep_auth_win; struct iwreq wrq; key_strikes keystr; int value; wep_auth_win = create_inputwin(6, 60,15, 4); wattron(wep_auth_win, A_BOLD); CancelExit(wep_auth_win, 1, 30); mvwprintw(wep_auth_win, 1,1, "Authentication Type"); mvwprintw(wep_auth_win, 2,1, "Set Type (0 for Open System, 1 for Shared Key) : "); DECL_KEYSTR(wep_auth_win, wep_win, 1, 2, 50) if (KbdPrompt(&keystr) < 0) return 0; value = keystr.int_val; if((value<0)||(value>1)) { ErrorWin("Invalid Authentication Type!!!"); return -EINVAL; } pEncryptionInfo->AuthenticationType = value; strcpy(wrq.ifr_name, cname); wrq.u.data.pointer = (caddr_t)pEncryptionInfo; wrq.u.data.length = sizeof(ENCRYPTION_INFO); wrq.u.data.flags = pEncryptionInfo->WepKeyToUse+1; wrq.u.data.flags |= (pEncryptionInfo->EncryptionLevel ? IW_ENCODE_ENABLED : IW_ENCODE_DISABLED); wrq.u.data.flags |= (pEncryptionInfo->AuthenticationType == C80211_MGMT_AAN_OPENSYSTEM ? IW_ENCODE_OPEN : IW_ENCODE_RESTRICTED); if(pEncryptionInfo->EncryptionLevel) wrq.u.data.length = (pEncryptionInfo->EncryptionLevel == WEP_64BIT ? 5 : 13); else wrq.u.data.length = 0; wrq.u.data.pointer = pEncryptionInfo->KeyMaterial[pEncryptionInfo->WepKeyToUse]; if (ioctl(fd, SIOCSIWENCODE, &wrq) < 0) { ErrorWin("Failed to Set Authentication Type!!!"); return -EIO; } return 0;}//*****************************************!!!telos tetarths**********************void print_wep_menu(WINDOW *wep_win, int wep_reverse){ int x, y, i; x = 4; y = 3; box(wep_win, 0, 0); HEADER(wep_win, "Security Menu (NO changes are applied until Auth.Type is SET)") for(i = 0; i < wep_config_choices; i++) { if(wep_reverse == i + 1) /* High reverse the present choice */ { wattron(wep_win, A_REVERSE); wattron(wep_win, A_BOLD); mvwprintw(wep_win, y, x, "%s", wep_choices[i]); wattroff(wep_win, A_BOLD); wattroff(wep_win, A_REVERSE); } else mvwprintw(wep_win, y, x, "%s", wep_choices[i]); y++; } wrefresh(wep_win);}int KbdPrompt(key_strikes *keystr){ int c, strindx=0; int exitloop=0; wrefresh(keystr->inputwin); keypad(keystr->inputwin, TRUE); do { if(strindx < keystr->get_max) echo(); else noecho(); c = mvwgetch(keystr->inputwin, keystr->inp_y, keystr->inp_x + strindx); switch(c) { case KEY_F(1): keystr->str_val[0] = '\0'; exitloop=-1; break; case KEY_BACKSPACE: noecho(); if(strindx>0) strindx--; mvwdelch(keystr->inputwin, keystr->inp_y, keystr->inp_x + strindx); wrefresh(keystr->inputwin); break; case 10: /* KEY_ENTER */ keystr->str_val[strindx]='\0'; exitloop=1; break; default: if(strindx < keystr->get_max) { keystr->str_val[strindx++]=c; wrefresh(keystr->inputwin); } break; } } while(!exitloop); /* return to parent window display */ noecho(); wclear(keystr->inputwin); keypad(keystr->inputwin, FALSE); destroy_win(keystr->inputwin); redrawwin(keystr->parentwin);/* truncate string to int, just in case it is needed */ keystr->int_val = atoi(keystr->str_val); return exitloop;} void ErrorWin(const char* errmsg){ WINDOW *errwin; errwin = newwin(6, 60,15, 4); box(errwin, 0, 0); wattron(errwin, A_BOLD); wattron(errwin, COLOR_PAIR(1)); mvwprintw(errwin, 2, 30-strlen(errmsg)/2, errmsg); mvwprintw(errwin, 4, 23, "Press Any Key"); wattroff(errwin, COLOR_PAIR(1)); wattroff(errwin, A_BOLD); wrefresh(errwin); getch(); wclear(errwin); destroy_win(errwin);}void CancelExit(WINDOW *win, int y, int x){ wattron(win, A_BOLD); wattron(win, COLOR_PAIR(1)); mvwprintw(win, y, x, "Cancel or Exit-> Press F1"); wattroff(win, COLOR_PAIR(1)); wattroff(win, A_BOLD);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -