| 1 | package Net::UCP::Common; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008007; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw(STX ETX UCP_DELIMITER DEF_SMSC_PORT ACK NACK DEBUG) ] ); | |||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 13 | 1 | our @EXPORT = qw(); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant STX => chr(2); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant ETX => chr(3); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use constant UCP_DELIMITER => '/'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use constant DEF_SMSC_PORT => 3024; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use constant ACK => 'A'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use constant NACK => 'N'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use constant DEBUG => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 28 | 1 | bless($self, shift())->_init(@_); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Calculate packet checksum | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub checksum { | ||||||||||||||||||||||||||
|
Subroutine
checksum: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 1 | shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | my $checksum; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | defined($_[0]) || return(0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | map {$checksum += ord} (split //,pop @_); | |||||||||||||||||||||||||||
| 39 | 1 | sprintf("%02X", $checksum%256); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Calculate data length | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub data_len { | ||||||||||||||||||||||||||
|
Subroutine
data_len: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 1 | shift; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | defined($_[0]) || return(0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | my $len = length(pop @_) + 17; | |||||||||||||||||||||||||||
| 49 | 1 | for(1..(5-length($len))) { | |||||||||||||||||||||||||||
| 50 | 3 | $len = '0' . $len; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | $len; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub decode_7bit { | ||||||||||||||||||||||||||
|
Subroutine
decode_7bit: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my ($oadc) = shift; | |||||||||||||||||||||||||||
| 60 | 0 | my ($msg,$bits); | |||||||||||||||||||||||||||
| 61 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $ud = $oadc || ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
$oadc || ''
MC/DC0%0/1
$oadc || ''
$oadc
Truth table0%0/2
A
A= $oadc
| |||||||||||||||||||||||||||||
| 63 | 0 | my $len = length($ud); | |||||||||||||||||||||||||||
| 64 | 0 | $msg = ""; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $byte = unpack('b8', pack('H2', substr($ud, 0, 2))); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | while (($cnt < length($ud)) && (length($msg) < $len)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cnt < length $ud and length $msg < $len
MC/DC0%0/2
$cnt < length $ud and length $msg < $len
$cnt < length $ud
length $msg < $len
Truth table0%0/3
A and B
A= $cnt < length $udB= length $msg < $len
| |||||||||||||||||||||||||||||
| 69 | 0 | $msg .= pack('b7', $byte); | |||||||||||||||||||||||||||
| 70 | 0 | $byte = substr($byte,7,length($byte)-7); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( (length( $byte ) < 7) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $cnt+=2; | |||||||||||||||||||||||||||
| 73 | 0 | $byte = $byte.unpack('b8', pack('H2', substr($ud, $cnt, 2))); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | return $msg; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | #use Encode is the best solution | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub encode_7bit { | ||||||||||||||||||||||||||
|
Subroutine
encode_7bit: called CC=8 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 1 | my($self, $msg) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | my($bit_string, $user_data) = ('',''); | |||||||||||||||||||||||||||
| 85 | 1 | my($octet, $rest); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | defined($msg) && length($msg) || return('00'); # Zero length user data. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $msg and length $msg
MC/DC0%0/2
defined $msg and length $msg
defined $msg
length $msg
Truth table33%1/3
A and B
A= defined $msgB= length $msg
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | for(split(//,$msg)) { | |||||||||||||||||||||||||||
| 90 | 5 | $bit_string.=unpack('b7',$_); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | while(defined($bit_string) && (length($bit_string))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $bit_string and length $bit_string
MC/DC50%1/2
defined $bit_string and length $bit_string
defined $bit_string
length $bit_string
Truth table66%2/3
A and B
A= defined $bit_stringB= length $bit_string
| |||||||||||||||||||||||||||||
| 94 | 5 | $rest = $octet = substr($bit_string,0,8); | |||||||||||||||||||||||||||
| 95 | 5 | $user_data .= unpack("H2",pack("b8",substr($octet.'0'x7,0,8))); | |||||||||||||||||||||||||||
| 96 | 5 | ▶ | $bit_string = (length($bit_string) > 8) ? substr($bit_string,8) : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | ▶ | sprintf("%02X", length($rest) < 5 ? length($user_data)-1 : length($user_data)).uc($user_data); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub convert_sms_to_ascii { | ||||||||||||||||||||||||||
|
Subroutine
convert_sms_to_ascii: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | 0 | my $msg = shift; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $msg =~ tr{\x00\x02\x05\x04\x06\x07\x08\x11\x5f\x7f} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | {\x40\x24\xe8\xe9\xf9\xec\xf2\x5f\xa7\xe0} if defined $msg; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | return $msg; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub convert_ascii_to_sms { | ||||||||||||||||||||||||||
|
Subroutine
convert_ascii_to_sms: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | 0 | my $msg = shift; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $msg =~ tr{\x40\x24\xe8\xe9\xf9\xec\xf2\x5f\xa7\xe0} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | {\x00\x02\x05\x04\x06\x07\x08\x11\x5f\x7f} if defined $msg; | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return $msg; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub ia5_decode { | ||||||||||||||||||||||||||
|
Subroutine
ia5_decode: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | 1 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | my $tmp = ""; | |||||||||||||||||||||||||||
| 128 | 1 | my $out = ""; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | while (length($msg)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 3 | ($tmp,$msg) = ($msg =~ /(..)(.*)/); | |||||||||||||||||||||||||||
| 132 | 3 | $out .= sprintf("%s", chr(hex($tmp))); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | return $out; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | ▶ | sub ia5_encode { shift; join('',map {sprintf "%02X", ord} split(//,pop(@_))); } | ||||||||||||||||||||||||||
|
Subroutine
ia5_encode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub error_by_code { | ||||||||||||||||||||||||||
|
Subroutine
error_by_code: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $ec = shift || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 144 | 0 | return $self->{EC}->{$ec}; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | my %ec_string = ( | |||||||||||||||||||||||||||
| 151 | '' => 'Unknown error code', | ||||||||||||||||||||||||||||
| 152 | '01' => 'Checksum error', | ||||||||||||||||||||||||||||
| 153 | '02' => 'Syntax error', | ||||||||||||||||||||||||||||
| 154 | '04' => 'Operation not allowed (at this point in time)', | ||||||||||||||||||||||||||||
| 155 | '05' => 'Call barring active', | ||||||||||||||||||||||||||||
| 156 | '06' => 'AdC invalid', | ||||||||||||||||||||||||||||
| 157 | '07' => 'Authentication failure', | ||||||||||||||||||||||||||||
| 158 | '08' => 'Legitimisation code for all calls, failure', | ||||||||||||||||||||||||||||
| 159 | '24' => 'Message too long', | ||||||||||||||||||||||||||||
| 160 | '26' => 'Message type not valid for the pager type', | ||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | $self->{EC} = %ec_string; | |||||||||||||||||||||||||||
| 164 | 1 | $self; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 1 | 1; | |||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||