8 $opt_r = "/dev/ttyUSB2";
9 $opt_s = "/dev/ttyUSB0";
10 $conv = Text
::Iconv
->new('utf16be','utf8');
14 Usage
: $0 [-r input_port
] [-s output_port
] [-n
] [-h
] [-v
] [-w
] [-i
] ussd_msg
17 Send
and receive
7-bit PDU
-encoded USSD messages
.
18 Written
and tested
for Huawei E1550 GSM
/UMTS USB modem
.
21 -r port Port to receive data from
. Default
: $opt_r
22 -s port Port to
send AT commands to
. Default
: $opt_s
23 -n Do
not send any data to port
. Useful with
-v
.
26 -i Use iconv
[from utf16be to utf8
] to reply
27 -w reply workaround
(try it
if script can
not decode reply
)
30 sub HELP_MESSAGE
{print "$USAGE\n"; exit;}
31 sub VERSION_MESSAGE
{};
32 getopts
('r:s:hnvwi');
33 HELP_MESSAGE
() and exit if (! $ARGV[0]) or defined($opt_h);
35 print "USSD MSG: $ARGV[0]\n" if $opt_v;
36 my $ussd_req = Device
::Gsm
::Pdu
::encode_text7
($ARGV[0]);
38 print "PDU ENCODED: $ussd_req\n" if $opt_v;
42 open (SENDPORT
, '+<', $opt_s) or die "Can't open '$opt_s': $!\n";
43 print SENDPORT
'AT+CUSD=1,',$ussd_req,",15\r\n";
45 open (RCVPORT
, $opt_r) or die "Can't open '$opt_r': $!\n";
46 print "Waiting for USSD reply...\n" if $opt_v;
49 die "USSD ERROR\n" if $_ eq "+CUSD: 2";
50 if (/^\+CUSD: 0,\"([A-F0-9]+)\"/) {
52 print "PDU USSD REPLY: $ussd_reply\n" if $opt_v;
55 print "Got unknown USSD message: $_\n" if /^\+CUSD:/ and $opt_v;
60 $iconved_reply = $conv->convert(pack('H*', $ussd_reply));
61 $decoded_ussd_reply = $opt_w ?
pack('H*', $ussd_reply) : Device
::Gsm
::Pdu
::decode_text7
('00'.$ussd_reply);
62 print STDOUT
"USSD REPLY: ".($opt_i ?
$iconved_reply: $decoded_ussd_reply)."\n";
66 print "No USSD reply!\n";