Advertisement
Guest User

balans

a guest
Mar 31st, 2011
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.72 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2.  
  3. use Getopt::Std;
  4. use Device::Gsm::Pdu;
  5.  
  6. # defaults
  7. $opt_r = "/dev/cuaU0.2";
  8. $opt_s = "/dev/cuaU0.2";
  9.  
  10. my $USAGE = <<__EOU;
  11.  
  12. Usage: $0 [-i input_port] [-o output_port] [-n] [-h] [-v] ussd_msg
  13.  
  14. Description:
  15.   Send and receive 7-bit PDU-encoded USSD messages.
  16.   Written and tested for Huawei E1550 GSM/UMTS USB modem.
  17.  
  18. Options:
  19.   -r port   Port to receive data from. Default: $opt_r
  20.   -s port   Port to send AT commands to. Default: $opt_s
  21.   -n        Do not send any data to port. Useful with -v.
  22.   -h        Print this help.
  23.   -v        Be verbose.
  24. __EOU
  25.  
  26. sub HELP_MESSAGE {print "$USAGE\n"; exit;}
  27. sub VERSION_MESSAGE {};
  28. getopts ('i:o:hnv');
  29. HELP_MESSAGE() and exit if (! $ARGV[0]) or defined($opt_h);
  30.  
  31. print "USSD MSG: $ARGV[0]\n" if $opt_v;
  32. my $ussd_req = Device::Gsm::Pdu::encode_text7($ARGV[0]);
  33. $ussd_req =~ s/^..//;
  34. print "PDU ENCODED: $ussd_req\n" if $opt_v;
  35.  
  36. my $ussd_reply;
  37. if (! $opt_n) {
  38.     open (SENDPORT, '+<', $opt_s) or die "Can't open '$opt_s': $!\n";
  39.     print SENDPORT 'AT+CUSD=1,',$ussd_req,",15\r\n";
  40.     close SENDPORT;
  41.     open (RCVPORT, $opt_r) or die "Can't open '$opt_r': $!\n";
  42.     print "Waiting for USSD reply...\n" if $opt_v;
  43.     while (<RCVPORT>) {
  44.         chomp;
  45.         die "USSD ERROR\n" if $_ eq "+CUSD: 2";
  46.         if (/^\+CUSD: 0,\"([A-F0-9]+)\"/) {
  47.             $ussd_reply = $1;
  48.             print "PDU USSD REPLY: $ussd_reply\n" if $opt_v;
  49.             last;
  50.         }
  51.         print "Got unknown USSD message: $_\n" if /^\+CUSD:/ and $opt_v;
  52.     }
  53. }
  54.  
  55. if ($ussd_reply) {
  56.     $decoded_ussd_reply = Device::Gsm::Pdu::decode_text_UCS2('00'.$ussd_reply);
  57.     print STDOUT "USSD REPLY: $decoded_ussd_reply\n";
  58. }
  59. else {print "No USSD reply!\n";}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement