7 use GSM::SMS::NBS::Message;
8 use GSM::SMS::NBS::Stack;
9 use GSM::SMS::OTA::RTTTL;
10 use GSM::SMS::OTA::CLIicon;
11 use GSM::SMS::OTA::Operatorlogo;
12 use GSM::SMS::OTA::VCard;
13 use GSM::SMS::OTA::Config;
14 use GSM::SMS::Transport;
23 my $class = ref($proto) || $proto;
27 $self->{'__CONFIG_FILE__'} = shift;
28 return undef unless $self->{'__TRANSPORT__'} = GSM::SMS::Transport->new( $self->{'__CONFIG_FILE__'});
29 $self->{'__STACK__'} = GSM::SMS::NBS::Stack->new( -transport => $self->{'__TRANSPORT__'} );
37 my ($self, $msisdn, $message, $dport, $sport, $dcs ) = @_;
40 my $transport = $self->{'__TRANSPORT__'};
42 my $nbs_message = GSM::SMS::NBS::Message->new();
43 $nbs_message->create($msisdn, $message, $dport, $sport, $dcs);
44 foreach my $frame ( @{$nbs_message->get_frames()} ) {
45 # transport->send returns -1 on failure.
46 $ret = -1 if $transport->send($msisdn, $frame);
55 my ($self, $msisdn, $rtttlstring) = @_;
57 if ( my $error = OTARTTTL_check($rtttlstring) ) {
61 my $music = OTARTTTL_makestream($rtttlstring);
62 return $self->sendto( $msisdn, $music, OTARTTTL_PORT);
68 sub sendOperatorLogo_b64 {
69 my ($self, $msisdn, $country, $operator, $b64, $format) = @_;
71 my $ol = OTAOperatorlogo_fromb64( $country, $operator, $b64, $format );
72 return $self->sendto( $msisdn, $ol, OTAOperatorlogo_PORT);
78 sub sendOperatorLogo_file {
79 my ($self, $msisdn, $country, $operator, $file ) = @_;
81 my $ol = OTAOperatorlogo_fromfile( $country, $operator, $file );
82 return $self->sendto($msisdn, $ol, OTAOperatorlogo_PORT);
88 sub sendGroupGraphic_b64 {
89 my ($self, $msisdn, $b64, $format) = @_;
91 my $gg = OTACLIicon_fromb64( $b64, $format );
92 return $self->sendto($msisdn, $gg, OTACLIicon_PORT);
98 sub sendGroupGraphic_file {
99 my ($self, $msisdn, $file) = @_;
101 my $gg = OTACLIicon_fromfile( $file );
103 return $self->sendto($msisdn, $gg, OTACLIicon_PORT);
110 my ($self, $msisdn, $lname, $fname, $phone) = @_;
112 my $vcard = OTAVcard_makestream( $last, $first, $phone );
113 return $self->sendto( $msisdn, $vcard, OTAVcard_PORT);
120 my ($self, $msisdn, $bearer, $connection, $auth, $type, $speed, $proxy, $home, $uid, $pwd, $phone, $name) = @_;
123 my $ota = OTAConfig_makestream( $bearer, $connection, $auth, $type, $speed, $proxy, $home, $uid, $pwd, $phone, $name);
125 $ret = $self->sendto( $msisdn, $ota, OTAConfig_PORT, 9200);
131 # send SMS text message
133 sub sendSMSTextMessage {
134 my ($self, $msisdn, $msg, $multipart) = @_;
138 while (length($msg) > 0) {
139 my $xmsg = substr($msg, 0, (length($msg)<160)?length($msg):160 );
140 $msg = substr($msg, 160, length($msg) - 160);
141 $ret = -1 if $self->sendto( $msisdn, $xmsg, undef, undef, '7bit');
145 $msg = substr($msg, 0, (length($msg)<160)?length($msg):160 );
146 $ret = $self->sendto( $msisdn, $msg, undef , undef , '7bit');
148 return ($ret==-1)?$ret:$cnt;
152 # receive SMS message from stack
155 my ($self, $ref_originatingaddress, $ref_message, $ref_timestamp, $ref_transportname, $ref_port, $blocking) = @_;
157 my $stack = $self->{'__STACK__'};
158 return $stack->receive($ref_originatingaddress, $ref_message, $ref_timestamp, $ref_transportname, $ref_port, $blocking);
165 GSM::SMS::NBS - API for sending and receiving SMS messages.
171 my $nbs = GSM::SMS::NBS->new( $transportconfigfile );
175 $nbs->sendRTTTL( '+32475000000', $rtttl_string );
176 $nbs->sendOperatorLogo_b64( $msisdn, $countrycode, $operator, $b64, 'gif' );
177 $nbs->sendOperatorLogo_file( $msisdn, $countrycode, $operatorcode, $file );
178 $nbs->sendGroupGraphic_b64( $msisdn, $b64, 'png' );
179 $nbs->sendGroupGraphic_file( $msisdn, $file );
180 $nbs->sendVCard( $msisdn, $lastname, $firstname, $phonenumber );
181 $nbs->sendConfig( .... );
182 $nbs->sendSMSTextMessage( $msisdn, $message, $multipart );
186 my $originatingaddress;
193 $nbs->receive( \$originatingaddress,
201 print "I got a message from $originatingaddress\n";
206 This module is the API you would normally use to send and receive sms messages.
207 It exports all the important methods and hides some of the more complex things.
208 It needs a configuration file in it's constructor. The configuration is transport specific but looks like:
217 Look into the transport.cfg files in the examples on how to set it up.
223 my $nbs = GSM::SMS::NBS->new( $configfile );
225 This is the constructor, it expects a file name of a transport configuration as an argument.
226 All functions return -1 on failure, 0 on success.
228 =head2 sendSMSTextMessage
230 $nbs->sendSMSTextMessage( $msisdn, $msg, $multipart );
232 Send a text message ( $msg ) to the gsm number ( $msisdn ). If you set $multipart to true (!=0) the message will be split automatically in 160 char blocks. When $multipart is set to false it will be truncated at 160 characters.
236 $nbs->sendRTTTL( $msisdn, $rtttlstring );
238 Send a ringing tone ( $rtttlstring ) to the specified telephone number ( $msisdn ). The RTTTL ( Ringing Tone Tagged Text Language ) format is specified as described in the file rtttlsyntax.txt.
240 You can find a lot of information about RTTTL ( and a lot of ringing tones ) on the internet. Just point your favourite browser to your favourite searchengine and look for ringing tones.
242 =head2 sendGroupGraphic_b64
244 $nbs->sendGroupGraphic_b64( $msisdn, $b64, $format);
246 Send a group graphic, also called a Caller Line Identification icon ( CLIicon ),to the recipient indicated by the telephone number $msisdn. It expects a base 64 encoded image and the format the image is in, like 'gif', 'png'. To find out which image formats are supported, look at the superb package Image::Magick. The base 64 encoded image is just a serialisation of an image file, not of the image bitarray. The image is limited in size, it needs to be 71x14 pixels.
247 The base 64 encoding is used here because you maybe want to build a HTTP (XMLRPC ) gateway to send images. Without the _b64 method you would need to save the image file to disk and use the _file method, this is cumbersome ...
248 A group graphic is used to visually identify the group the caller belongs to. If you have a friend who calls you and his number is in the group 'friends', you probably would want to picture a pint of beer.
250 =head2 sendGroupGraphic_file
252 $nbs->sendGroupGraphic_file( $msisdn, $file);
254 Send a group graphic to $msisdn, use the image in file $file. The image must be 71x14 pixels.
256 =head2 sendOperatorLogo_b64
258 $nbs->sendOperatorLogo_b64( $msisdn, $country, $operator, $b64, $format);
260 An operator logo indicates the operator you are connected to for the moment. This is used to have a nice logo on your telephone all of the time. I have also heard the term 'branding' overhere.
261 You also need to provide a country code and operator code. I have assembled some of these and you can find them in the file codes.txt. These files will move into a seperate package, because you can find the operator and country codes programatically by using the first n numbers of the msisdn.
262 The method expects a base64 serialised image and the format of the image, 'gif', 'png', next to the receiving telephone number ( $msisdn ) and the country and operator code.
263 The image needs to be 71x14 pixels.
265 =head2 sendOperatorLogo_file
267 $nbs->sendOperatorLogo_file( $msisdn, $country, $operator, $file );
269 Send an operator logo to $msisdn, using the image in file $file.
273 $nbs->sendVCard( $msisdn, $lastname, $firstname, $telephone );
275 A VCard is a small business card, containing information about a person. It is not a GSM only standard, netscape uses vcards to identify the mail sender ( attach vcard option ). You can look at the complete VCard MIME specification in RFC 2425 and RFC 2426.
279 $nbs->sendConfig( $msisdn, $bearer, $connection, $auth, $type, $speed, $proxy, $home, $uid, $pwd, $phone, $name);
281 Send a WAP configuration to a WAP capable handset. It expects the following parameters:
283 The parameters in UPPERCASE are exported constants by the GSM::SMS::OTA::COnfig.
285 $msisdn Phonenumber recipient
287 $bearer OTA_BEARER_CSD | OTA_BEARER_SMS
289 The carrier used ( circuit switched data or sms ), WAP is
290 independent of the underlying connectivity layer.
292 $connection OTA_CONNECTIONTYPE_TEMPORARY
293 OTA_CONNECTIONTYPE_CONTINUOUS
295 You have to use continuous for CSD type of calls.
297 $auth OTA_CSD_AUTHTYPE_PAP
298 OTA_CSD_AUTHTYPE_CHAP
300 Use PAP or CHAP as authentication type. A CSD call is just
301 a data call, and as such can use a normal dial-in point.
303 $type OTA_CSD_CALLTYPE_ISDN
304 OTA_CSD_CALLTYPE_ANALOGUE
306 $speed OTA_CSD_CALLSPEED_9600
307 OTA_CSD_CALLSPEED_14400
308 OTA_CSD_CALLSPEED_AUTO
310 $proxy IP address of the WAP gateway to use.
312 $home URL of the homepage for this setting. e.g.
313 http://wap.domain.com
317 $pwd Dial-up password
319 $phone Dial-up telephone number
321 $name Nick name for this connection.
323 This feature has been tested on a Nokia 7110, but other Nokia
324 handsets are also supported.
328 $nbs->receive( \$originatingaddress,
336 This method is used for implementing bidirectional SMS. With you can receive incoming messages. The only transport ( for the moment ) that can receive SMS messages is the Serial transport.
338 The originatingaddress contains the sender msisdn number.
340 The message contains the ( concatenated ) message. A NBS message can be larger than 140 bytes, so a UDP like format is used to send fragements. The lower layers of the GSM::SMS package take care of the SAR ( Segmentation And Reassembly ).
342 The timestamp has the following format:
346 YY := 2 digits for the year ( 01 = 2001 )
347 MM := 2 digits for the month
348 DD := 2 digits for the day
349 HH := 2 digits for the hour
350 MM := 2 ditits for the minutes
351 SS := 2 digits for the seconds
354 Transportname contains the name of the transport as defined in the config file.
356 Port is the port number used to denote a specified service in the NBS stack.
358 my $originatingaddress;
365 $nbs->receive( \$originatingaddress,
373 print "I got a message from $originatingaddress\n";
377 Probably a lot. I hope to get some bug reports ...
378 One odd behaviour is that the CSCA is not always set correctly.
379 If receiving works, but sending not ( on the serial transport ),
380 then issue the next command to the modem in e.g. minicom.
382 AT+CSCA="+32475161616"
383 ( For belgian proximus ... look at your operator
384 for correct csca address ).
388 Johan Van den Brande <johan@vandenbrande.com>