:pserver:anonymous@intra.tektonica.com:/opt/cvs - gsmperl - Fri Dec 21 07:37 CET...
[gsmperl.git] / GSM / SMS / OTA / Config.pm
1 package GSM::SMS::OTA::Config;
2
3 require Exporter;
4 @ISA = qw(Exporter);
5
6 $VERSION = '0.1';
7
8 @EXPORT = qw(   OTA_BEARER_CSD 
9                                 OTA_BEARER_SMS
10                                 OTA_CONNECTIONTYPE_TEMPORARY
11                                 OTA_CONNECTIONTYPE_CONTINUOUS
12                                 OTA_CSD_AUTHTYPE_PAP
13                                 OTA_CSD_AUTHTYPE_CHAP
14                                 OTA_CSD_CALLTYPE_ISDN
15                                 OTA_CSD_CALLTYPE_ANALOGUE
16                                 OTA_CSD_CALLSPEED_9600
17                                 OTA_CSD_CALLSPEED_AUTO
18                                 OTA_CSD_CALLSPEED_14400
19                                 OTAmakestream
20                                 OTAConfig_makestream
21                                 );
22
23 sub OTAConfig_makestream {
24         my ($bearer, $connection, $auth, $type, $speed, $proxy, $home, $uid, $pwd, $phone, $name) = @_; 
25         
26         # BEARER
27         my $_bearer;
28         if              ( $bearer eq "CSD" ) {
29                 $_bearer =  OTA_BEARER_CSD;
30         }
31         elsif   ( $bearer eq "SMS" ) {
32                 $_bearer = OTA_BEARER_SMS;
33         }
34         else {
35                 # print "Unknown bearer type: $bearer!\n";
36                 return;
37         }
38
39         # CONNECTION
40         my $_connection;
41         if              ( $connection eq "TEMPORARY" ) {
42                 $_connection = OTA_CONNECTIONTYPE_TEMPORARY;
43         }
44         elsif   ( $connection eq "CONTINUOUS" ) {
45                 $_connection = OTA_CONNECTIONTYPE_CONTINUOUS;
46         }
47         else {
48                 # print "Unknown connection type: $connection!\n";
49                 return;
50         }
51
52         # AUTH
53         my $_auth;
54         if              ( $auth eq "PAP" ) {
55                 $_auth = OTA_CSD_AUTHTYPE_PAP;
56         }
57         elsif   ( $auth eq "CHAP" ) {
58                 $_auth = OTA_CSD_AUTHTYPE_CHAP;
59         }
60         else {
61                 # print "Unknwon authentication type: $auth!\n";
62                 return;
63         }
64
65         # TYPE
66         my $_type;
67         if              ( $type eq "ISDN" ) {
68                 $_type = OTA_CSD_CALLTYPE_ISDN;
69         }
70         elsif   ( $type eq "ANALOGUE" ) {
71                 $_type = OTA_CSD_CALLTYPE_ANALOGUE;
72         }
73         else {
74                 # print "Unknown calltype: $type!\n";
75                 return;
76         }
77
78         # SPEED
79         my $_speed;
80         if              ( $speed eq "9600" ) {
81                 $_speed = OTA_CSD_CALLSPEED_9600;
82         }
83         elsif   ( $speed eq "AUTO" ) {
84                 $_speed = OTA_CSD_CALLSPEED_AUTO;
85         }
86         elsif   ( $speed eq "14400" ) {
87                 $_speed = OTA_CSD_CALLSPEED_14400;
88         }
89         else {
90                 # print "Unknown speed: $speed!\n";
91                 return;
92         }
93
94
95         # We do not check the other parameters  
96
97         my $ota = OTAmakestream(
98                 $_bearer,
99                 $proxy,
100                 $_connection,
101                 $phone,
102                 $_auth,
103                 $uid,
104                 $pwd,
105                                 $_type,
106                 $_speed,
107                 $home,
108                 $name);
109
110         return $ota;
111 }
112
113
114 sub OTAmakestream {
115         my (    $BEARER, 
116                         $PROXY, 
117                         $CONNECTIONTYPE,
118                         $CSD_DIALSTRING,
119                         $CSD_AUTHTYPE,
120                         $CSD_AUTHNAME,
121                         $CSD_AUTHSECRET,
122                         $CSD_CALLTYPE,
123                         $CSD_CALLSPEED,
124                         $URL,
125                         $NAME                           )       =       @_;     
126
127
128
129 my $_PROXY                      = OTAencode_8bit( $PROXY );
130 my $_CSD_DIALSTRING     = OTAencode_8bit( $CSD_DIALSTRING );
131 my $_CSD_AUTHNAME       = OTAencode_8bit( $CSD_AUTHNAME );
132 my $_CSD_AUTHSECRET     = OTAencode_8bit( $CSD_AUTHSECRET );
133 my $_URL                        = OTAencode_8bit( $URL );
134 my $_NAME                       = OTAencode_8bit( $NAME );
135
136
137
138 my $ota = <<END;
139 01
140 06
141 04
142 03
143 9481EA00
144 010045C606
145 018712${BEARER} 
146 0187131103
147 ${_PROXY}00 
148 018714${CONNECTIONTYPE}
149 0187211103
150 ${_CSD_DIALSTRING}00
151 018722${CSD_AUTHTYPE}
152 0187231103
153 ${_CSD_AUTHNAME}00
154 0187241103
155 ${_CSD_AUTHSECRET}00 
156 018728${CSD_CALLTYPE}
157 018729${CSD_CALLSPEED}
158 01
159 0186071103
160 ${_URL}00 
161 01C608
162 0187151103
163 ${_NAME}00 
164 01
165 01
166 01
167 END
168
169 $ota=~s/[\n\s]//ig;
170 return $ota;
171
172 }
173
174 # constant  definition
175 use constant    OTA_BEARER_CSD => '45'; 
176 use constant    OTA_BEARER_SMS => '41'; 
177 use constant    OTA_CONNECTIONTYPE_TEMPORARY => '60';
178 use constant    OTA_CONNECTIONTYPE_CONTINUOUS => '61';
179 use constant    OTA_CSD_AUTHTYPE_PAP => '70';
180 use constant    OTA_CSD_AUTHTYPE_CHAP => '71';
181 use constant    OTA_CSD_CALLTYPE_ISDN => '73';
182 use constant    OTA_CSD_CALLTYPE_ANALOGUE => '72';
183 use constant    OTA_CSD_CALLSPEED_9600 => '6B';
184 use constant    OTA_CSD_CALLSPEED_AUTO => '6A';
185 use constant    OTA_CSD_CALLSPEED_14400 => '6C';
186 use constant    OTAConfig_PORT => 49999;  
187
188 # help functions
189
190 sub OTAdecode_8bit {
191         my ($ud) = @_;
192         my $msg;
193
194         while (length($ud)) {
195                 $msg .= pack('H2',substr($ud,0,2));
196                 $ud = substr($ud,2);
197         }
198         return $msg;
199 }
200
201
202 sub OTAencode_8bit {
203         my ($ud) = @_;
204         my $msg;
205
206         while (length($ud)) {
207                $msg .= sprintf("%.2X", ord(substr($ud,0,1)));
208                $ud = substr($ud,1);
209         }
210         return $msg;
211 }
212
213
214 1;
215
216 =head1 NAME
217
218 GSM::SMS::OTA::Config
219
220 =head1 DESCRIPTION
221
222 Create an "over the air" configuration message to configure a WAP telephone with a proper setting. I only tested this one on Nokia phones (7110). This is very useful to "bulk configurate" WAP telephones.
223
224 =head1 METHODS
225
226 =head2 OTAConfig_makestream
227
228         $stream = OTAConfig_makestream(
229                                         $bearer,
230                                         $connection,
231                                         $auth,
232                                         $type,
233                                         $speed,
234                                         $proxy,
235                                         $home,
236                                         $uid,
237                                         $pwd,
238                                         $phone,
239                                         $name
240                                         );
241
242         $bearer:
243                 CSD | SMS
244
245         $connection:
246                 TEMPORARY | CONTINUOUS
247
248         $auth:
249                 PAP | CHAP
250
251         $type:
252                 ISDN | ANALOGUE
253
254         $speed:
255                 9600 | 14400 | AUTO
256
257         $proxy:
258                 IP address of wap gateway to use
259
260         $home:
261                 URL of home address
262
263         $uid:
264                 Username for dialin authentication
265
266         $pwd:
267                 Password for dialin authentification
268
269         $phone:
270                 Phone number to dial for dial-in connection
271
272         $name:
273                 Nick name you can give for this connection
274
275 =head1 AUTHOR
276
277 Johan Van den Brande <johan@vandenbrande.com>
278