summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/gprs/GPRS_NNI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/gprs/GPRS_NNI.cpp231
1 files changed, 231 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp
new file mode 100644
index 0000000..2f61cba
--- a/dev/null
+++ b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp
@@ -0,0 +1,231 @@
1#include <system.h>
2#include <netnode.h>
3#include "GPRSedit.h"
4#include "GPRS_NNI.h"
5#include "GPRS_NN.h"
6
7AGPRSDevice::AGPRSDevice( GPRSNetNode * PNN ) : ANetNodeInstance( PNN ) {
8 Data.APN = "";
9 Data.User = "";
10 Data.Password = "";
11 Data.DefaultGateway = 1;
12 Data.SetIfSet = 0;
13 Data.Debug = 0;
14 Data.Routing.setAutoDelete( TRUE );
15 GUI = 0;
16 RT = 0;
17}
18
19void AGPRSDevice::setSpecificAttribute( QString & A, QString & V ) {
20 if( A == "apn" ) {
21 Data.APN = V;
22 } else if( A == "user" ) {
23 Data.User = V;
24 } else if( A == "password" ) {
25 Data.Password = V;
26 } else if( A == "dns2" ) {
27 Data.DNS2 = V;
28 } else if( A == "dns1" ) {
29 Data.DNS1 = V;
30 } else if( A == "defaultgateway" ) {
31 Data.DefaultGateway = (V=="yes");
32 } else if( A == "setifset" ) {
33 Data.SetIfSet = (V == "yes");
34 } else if( A == "routes" ) {
35 Data.Routing.resize( V.toULong() );
36 } else if( A.startsWith( "route" ) ) {
37 QStringList SL = QStringList::split( "/", V );
38 GPRSRoutingEntry * E = new GPRSRoutingEntry;
39
40 E->Address = SL[0];
41 E->Mask = SL[1].toULong();
42
43 Data.Routing.insert( A.mid(5).toULong(), E );
44 } else if( A == "debug" ) {
45 Data.Debug = V.toShort();
46 }
47}
48
49void AGPRSDevice::saveSpecificAttribute( QTextStream & TS ) {
50 TS << "apn=" << Data.APN << endl;
51 TS << "user=" << Data.User << endl;
52 TS << "password=" << Data.Password << endl;
53 TS << "dns1=" << Data.DNS1 << endl;
54 TS << "dns2=" << Data.DNS2 << endl;
55 TS << "defaultgateway=" << ( (Data.DefaultGateway) ? "yes" : "no" ) << endl;
56 TS << "setifset=" << ((Data.SetIfSet) ? "yes" : "no") << endl;
57 TS << "debug=" << Data.Debug << endl;
58
59 TS << "routes=" << Data.Routing.count() << oendl;
60 for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) {
61 TS << "route" << i << "="
62 << Data.Routing[i]->Address
63 << "/"
64 << Data.Routing[i]->Mask
65 << oendl;
66 }
67}
68
69QWidget * AGPRSDevice::edit( QWidget * parent ) {
70 GUI = new GPRSEdit( parent );
71 GUI->showData( Data );
72 return GUI;
73}
74
75QString AGPRSDevice::acceptable( void ) {
76 return ( GUI ) ? GUI->acceptable( ) : QString();
77}
78
79void AGPRSDevice::commit( void ) {
80 if( GUI && GUI->commit( Data ) )
81 setModified( 1 );
82}
83
84bool AGPRSDevice::hasDataForFile( SystemFile & S ) {
85 return S.name() == "pap-secrets" ||
86 S.name() == "peers" ||
87 S.name() == "extra" ||
88 S.name() == "chatscripts" ;
89}
90
91short AGPRSDevice::generateFile( SystemFile & SF,
92 long
93 ) {
94
95 if( SF.name() == "pap-secrets" ) {
96 SF << Data.User
97 << " * "
98 << Data.Password
99 << " *"
100 << endl;
101 return 0;
102 } else if( SF.name() == "chatscripts" ) {
103 SF << "SAY \"Starting\\n\"" << oendl;
104 SF << "ECHO OFF" << oendl;
105 SF << "ABORT BUSY" << oendl;
106 SF << "ABORT ERROR" << oendl;
107 SF << "ABORT VOICE" << oendl;
108 SF << "ABORT \"NO CARRIER\"" << oendl;
109 SF << "ABORT \"NO DIALTONE\"" << oendl;
110 SF << "\"\" AT" << oendl;
111 SF << "OK AT+CGATT=1" << oendl;
112 SF << "OK AT+CGDCONT=1,\"IP\",\""
113 << Data.APN
114 << "\""
115 << oendl;
116 SF << "OK ATD*99***1#\\n" << oendl;
117 SF << "TIMEOUT 10" << oendl;
118 SF << "CONNECT \"\"" << oendl;
119 SF << "SAY \"READY\\n\"" << oendl;
120 return 0;
121 } else if( SF.name() == "peers" ) {
122 SF << "noauth" << oendl;
123 SF << "user " << Data.User << oendl;
124 SF << "connect \"/usr/sbin/chat -s -v -f /etc/chatscripts/"
125 << removeSpaces( connection()->name() )
126 << "\""
127 << oendl;
128 SF << "ipcp-accept-local" << oendl;
129 SF << "ipcp-accept-remote" << oendl;
130 if( Data.DefaultGateway ) {
131 SF << "defaultroute" << oendl;
132 if( Data.SetIfSet ) {
133 SF << "replacedefaultroute" << oendl;
134 }
135 }
136 if( Data.Debug ) {
137 SF << "logfile /tmp/"
138 << removeSpaces( connection()->name() )
139 << oendl;
140 for( int i = 0; i < Data.Debug; i ++ ) {
141 SF << "debug" << oendl;
142 }
143 }
144 SF << "nocrtscts" << oendl;
145 SF << "local" << oendl;
146 SF << "lcp-echo-interval 0" << oendl;
147 SF << "lcp-echo-failure 0" << oendl;
148 SF << "usepeerdns" << oendl;
149 SF << "linkname " << removeSpaces( connection()->name() ) << oendl;
150 SF << "nopersist" << oendl;
151 SF << "ipparam " << removeSpaces( connection()->name() ) <<oendl;
152 SF << "maxfail 1" << oendl;
153 return 0;
154 } else if( SF.name() == "extra" ) {
155 unsigned long Bits;
156 // generate 'fixed' settings
157 for( unsigned int i = 0 ;
158 i < Data.Routing.count();
159 i ++ ) {
160 if( Data.Routing[i]->Mask == 32 ) {
161 Bits = 0xffffffff;
162 } else {
163 Bits = ~ ((1 << ((32-Data.Routing[i]->Mask))) - 1);
164 }
165 SF << "route add -net "
166 << Data.Routing[i]->Address
167 << " netmask "
168 << ((Bits&0xff000000)>>24)
169 << "."
170 << ((Bits&0x00ff0000)>>16)
171 << "."
172 << ((Bits&0x0000ff00)>>8)
173 << "."
174 << ((Bits&0x000000ff))
175 << " gw $PPP_REMOTE"
176 << oendl;
177 SF << "route del -net "
178 << Data.Routing[i]->Address
179 << " netmask "
180 << ((Bits&0xff000000)>>24)
181 << "."
182 << ((Bits&0x00ff0000)>>16)
183 << "."
184 << ((Bits&0x0000ff00)>>8)
185 << "."
186 << ((Bits&0x000000ff))
187 << " gw $PPP_REMOTE"
188 << oendl;
189 }
190
191 if( ! Data.DNS1.isEmpty() ) {
192 SF << "nameserver "
193 << Data.DNS1
194 << " # profile "
195 << removeSpaces( connection()->name() )
196 <<oendl;
197 }
198
199 if( ! Data.DNS2.isEmpty() ) {
200 SF << "nameserver "
201 << Data.DNS2
202 << " # profile "
203 << removeSpaces( connection()->name() )
204 <<oendl;
205 }
206 }
207 return 1;
208}
209
210bool AGPRSDevice::openFile( SystemFile & SF ) {
211 if( SF.name() == "peers" ) {
212 SF.setPath(
213 QString( "/etc/ppp/peers/" ) +
214 removeSpaces( connection()->name() )
215 );
216 return 1;
217 } else if ( SF.name() == "chatscripts" ) {
218 SF.setPath(
219 QString( "/etc/chatscripts/" ) +
220 removeSpaces( connection()->name() )
221 );
222 return 1;
223 } else if ( SF.name() == "extra" ) {
224 SF.setPath(
225 QString( "/etc/ppp/" ) +
226 removeSpaces( connection()->name() ) + ".fixed"
227 );
228 return 1;
229 }
230 return 0;
231}