1 #include <qapplication.h>
3 #include <qmessagebox.h>
7 #include <sys/socket.h>
10 #include <linux/wireless.h>
11 #include <asm/errno.h>
13 #include <sys/stat.h> /* for mode definitions */
14 #include <signal.h> /* for disable CTRL-C */
18 #include "raconfigui.h"
19 #include "countryform.h"
20 #include "cardselect.h"
21 #include "configapi.h"
24 #define LOCK_FILE "/tmp/.RaConfig25STA.lck"
26 PRT_PROFILE_SETTING RTMPProfile
=NULL
;
27 PRT_DEVICE_ADAPTER pDevice_Adpater
=NULL
;
28 bool G_bUserAdmin
= FALSE
;
29 bool G_bSupportAMode
= FALSE
;
31 char Configfile_name
[255];
32 UINT G_nCountryRegion
= REGSTR_COUNTRYREGION_FCC
;
35 int m_open_cards(int socket_id
)
39 char Device_Name
[255];
41 PRT_DEVICE_ADAPTER prtAdapter
=NULL
;
45 sprintf(name
, "ra%d", i
);
46 memset(Device_Name
, 0x00, 255);
47 if( OidQueryInformation(RT_OID_DEVICE_NAME
, socket_id
, name
, Device_Name
, 255) != 0)
50 if(memcmp(Device_Name
, NIC_DEVICE_NAME
, sizeof(NIC_DEVICE_NAME
)) == 0)
55 pDevice_Adpater
= (PRT_DEVICE_ADAPTER
) malloc(sizeof(RT_DEVICE_ADAPTER
));
58 pDevice_Adpater
->Device_Name
= (char *)malloc(strlen(name
)+1);
59 if(!pDevice_Adpater
->Device_Name
)
60 return (-1); // Not enough memory
61 strcpy(pDevice_Adpater
->Device_Name
, name
);
62 pDevice_Adpater
->Next
= NULL
;
63 prtAdapter
= pDevice_Adpater
;
66 return (-1); // Not enough memory
70 prtAdapter
->Next
= (PRT_DEVICE_ADAPTER
) malloc(sizeof(RT_DEVICE_ADAPTER
));
73 prtAdapter
= prtAdapter
->Next
;
74 prtAdapter
->Device_Name
= (char *)malloc(strlen(name
)+1);
75 if(!prtAdapter
->Device_Name
)
76 return (-1); // Not enough memory
77 strcpy(prtAdapter
->Device_Name
, name
);
78 prtAdapter
->Next
= NULL
;
81 return (-1); // Not enough memory
89 UCHAR
Get_CountryRegion()
91 char tmpCountryRegion
[10];
92 int getCountryFlag
=FALSE
;
95 if(getkeystring("Default", "CountryRegion", tmpCountryRegion
, 10, RT2500_SYSTEM_PATH
, RT2500_SYSTEM_DATA
) == TRUE
)
97 country
= atoi(tmpCountryRegion
);
98 if ((country
>= REGSTR_COUNTRYREGION_MINIMUM
) && (country
<= REGSTR_COUNTRYREGION_MAXIMUM
))
99 getCountryFlag
= TRUE
;
102 if( !getCountryFlag
)
104 CountryForm
*ctyForm
= new CountryForm
;
106 if(ctyForm
->exec() == QDialog::Accepted
)
108 country
= ctyForm
->GetRegionID();
109 sprintf(tmpCountryRegion
, "%d", country
);
111 writekeystring("Default", "CountryRegion", tmpCountryRegion
, RT2500_SYSTEM_PATH
, RT2500_SYSTEM_DATA
);
115 QMessageBox
*mb
= new QMessageBox();
116 mb
->setCaption("Information");
117 mb
->setText("This message dialog will pop up again next time, if no country region is selected.");
118 mb
->setIcon(QMessageBox::Information
);
119 mb
->setButtonText(0, "&Ok");
125 return ((UCHAR
)country
);
128 int main( int argc
, char ** argv
)
140 signal( SIGINT
, SIG_IGN
); /* disable CTRL-C */
141 QApplication
App( argc
, argv
);
145 G_bUserAdmin
= FALSE
;
146 QMessageBox
*mb
= new QMessageBox();
147 mb
->setCaption("Information");
148 mb
->setText("You do not have supper user's privilege!");
149 mb
->setIcon(QMessageBox::Information
);
150 mb
->setButtonText(0, "&Ok");
157 fd
=open(LOCK_FILE
, O_RDWR
| O_CREAT
| O_EXCL
);
158 if (fd
<0 && errno
==EEXIST
)
160 if((fileLCK
=fopen(LOCK_FILE
, "rb")) != NULL
)
162 fgets(buffer
, 255, fileLCK
);
163 sscanf(buffer
, "%d", &pid
);
165 sprintf(buffer
, "/proc/%d", pid
);
166 dirptr
= opendir(buffer
);
170 if((fileLCK
=fopen(LOCK_FILE
, "wb")) != NULL
)
172 fprintf(fileLCK
, "%d", getpid());
185 system("chmod a+rw " LOCK_FILE
);
186 system("chmod u-s " LOCK_FILE
); //remove -rwsrw-rw- *s*
187 sprintf(buffer
, "%d", getpid());
188 write(fd
, buffer
, strlen(buffer
));
194 QMessageBox
*mb
= new QMessageBox();
195 mb
->setCaption("Warning");
196 sprintf(buffer
, "There is an other program running, please close it and try again!\nPID=%d", pid
);
198 mb
->setIcon(QMessageBox::Critical
);
199 mb
->setButtonText(0, "&Ok");
205 if((socket_id
= Open_Socket()) < 0)
207 QMessageBox
*mb
= new QMessageBox();
208 mb
->setCaption("Warning");
209 mb
->setText("Open socket error!");
210 mb
->setIcon(QMessageBox::Critical
);
211 mb
->setButtonText(0, "&Exit");
217 adapter_num
= m_open_cards(socket_id
);
219 { //Not enough memory
220 QMessageBox
*mb
= new QMessageBox();
221 mb
->setCaption("Error");
222 mb
->setText("Device driver not found!");
223 mb
->setIcon(QMessageBox::Critical
);
224 mb
->setButtonText(0, "&Ok");
230 else if( adapter_num
==0)
232 QMessageBox
*mb
= new QMessageBox();
233 mb
->setCaption("Error");
234 mb
->setText("Device driver not found!");
235 mb
->setIcon(QMessageBox::Critical
);
236 mb
->setButtonText(0, "&Ok");
242 else if (adapter_num
== 1)
246 G_nCountryRegion
= Get_CountryRegion();
247 OidSetInformation(RT_OID_802_11_COUNTRY_REGION
, socket_id
, (char *)pDevice_Adpater
->Device_Name
, &G_nCountryRegion
, sizeof(G_nCountryRegion
));
250 w
= new RaConfigForm(socket_id
, pDevice_Adpater
->Device_Name
);
251 w
->resize( 600, 480 );
252 App
.setMainWidget(w
);
256 CardSelect
*cardSel
= new CardSelect(socket_id
, pDevice_Adpater
);
260 if (!cardSel
->isClickOk())
268 G_nCountryRegion
= Get_CountryRegion();
269 OidSetInformation(RT_OID_802_11_COUNTRY_REGION
, socket_id
, (char *)cardSel
->Get_Device_Name(), &G_nCountryRegion
, sizeof(G_nCountryRegion
));
272 w
= new RaConfigForm(socket_id
, cardSel
->Get_Device_Name());
273 w
->resize( 600, 480 );
274 App
.setMainWidget(w
);
278 App
.connect( &App
, SIGNAL( lastWindowClosed() ), &App
, SLOT( quit() ) );