line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::UCP::Common; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26583
|
use 5.008007; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
133
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(STX ETX UCP_DELIMITER DEF_SMSC_PORT ACK NACK DEBUG) ] ); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
13
|
|
|
|
|
|
|
our @EXPORT = qw(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use constant STX => chr(2); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
86
|
|
18
|
1
|
|
|
1
|
|
5
|
use constant ETX => chr(3); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
54
|
|
19
|
1
|
|
|
1
|
|
4
|
use constant UCP_DELIMITER => '/'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
20
|
1
|
|
|
1
|
|
4
|
use constant DEF_SMSC_PORT => 3024; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
21
|
1
|
|
|
1
|
|
3
|
use constant ACK => 'A'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
22
|
1
|
|
|
1
|
|
4
|
use constant NACK => 'N'; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
42
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
4
|
use constant DEBUG => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
968
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
1
|
|
|
1
|
0
|
12
|
my $self = {}; |
28
|
1
|
|
|
|
|
7
|
bless($self, shift())->_init(@_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Calculate packet checksum |
32
|
|
|
|
|
|
|
sub checksum { |
33
|
1
|
|
|
1
|
0
|
1842
|
shift; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
my $checksum; |
36
|
|
|
|
|
|
|
|
37
|
1
|
50
|
|
|
|
5
|
defined($_[0]) || return(0); |
38
|
1
|
|
|
|
|
8
|
map {$checksum += ord} (split //,pop @_); |
|
12
|
|
|
|
|
15
|
|
39
|
1
|
|
|
|
|
13
|
sprintf("%02X", $checksum%256); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Calculate data length |
44
|
|
|
|
|
|
|
sub data_len { |
45
|
1
|
|
|
1
|
0
|
2
|
shift; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
3
|
defined($_[0]) || return(0); |
48
|
1
|
|
|
|
|
3
|
my $len = length(pop @_) + 17; |
49
|
1
|
|
|
|
|
5
|
for(1..(5-length($len))) { |
50
|
3
|
|
|
|
|
15
|
$len = '0' . $len; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
4
|
$len; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub decode_7bit { |
57
|
0
|
|
|
0
|
0
|
0
|
shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my ($oadc) = shift; |
60
|
0
|
|
|
|
|
0
|
my ($msg,$bits); |
61
|
0
|
|
|
|
|
0
|
my $cnt = 0; |
62
|
0
|
|
0
|
|
|
0
|
my $ud = $oadc || ""; |
63
|
0
|
|
|
|
|
0
|
my $len = length($ud); |
64
|
0
|
|
|
|
|
0
|
$msg = ""; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
my $byte = unpack('b8', pack('H2', substr($ud, 0, 2))); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
0
|
|
|
0
|
while (($cnt < length($ud)) && (length($msg) < $len)) { |
69
|
0
|
|
|
|
|
0
|
$msg .= pack('b7', $byte); |
70
|
0
|
|
|
|
|
0
|
$byte = substr($byte,7,length($byte)-7); |
71
|
0
|
0
|
|
|
|
0
|
if ( (length( $byte ) < 7) ) { |
72
|
0
|
|
|
|
|
0
|
$cnt+=2; |
73
|
0
|
|
|
|
|
0
|
$byte = $byte.unpack('b8', pack('H2', substr($ud, $cnt, 2))); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return $msg; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#use Encode is the best solution |
81
|
|
|
|
|
|
|
sub encode_7bit { |
82
|
1
|
|
|
1
|
0
|
25
|
my($self, $msg) = @_; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
3
|
my($bit_string, $user_data) = ('',''); |
85
|
1
|
|
|
|
|
2
|
my($octet, $rest); |
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
33
|
|
|
9
|
defined($msg) && length($msg) || return('00'); # Zero length user data. |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
5
|
for(split(//,$msg)) { |
90
|
5
|
|
|
|
|
13
|
$bit_string.=unpack('b7',$_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
66
|
|
|
7
|
while(defined($bit_string) && (length($bit_string))) { |
94
|
5
|
|
|
|
|
7
|
$rest = $octet = substr($bit_string,0,8); |
95
|
5
|
|
|
|
|
14
|
$user_data .= unpack("H2",pack("b8",substr($octet.'0'x7,0,8))); |
96
|
5
|
100
|
|
|
|
23
|
$bit_string = (length($bit_string) > 8) ? substr($bit_string,8) : ''; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
50
|
|
|
|
9
|
sprintf("%02X", length($rest) < 5 ? length($user_data)-1 : length($user_data)).uc($user_data); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub convert_sms_to_ascii { |
103
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
104
|
0
|
|
|
|
|
0
|
my $msg = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
0
|
$msg =~ tr{\x00\x02\x05\x04\x06\x07\x08\x11\x5f\x7f} |
107
|
|
|
|
|
|
|
{\x40\x24\xe8\xe9\xf9\xec\xf2\x5f\xa7\xe0} if defined $msg; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
return $msg; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub convert_ascii_to_sms { |
114
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
115
|
0
|
|
|
|
|
0
|
my $msg = shift; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
0
|
$msg =~ tr{\x40\x24\xe8\xe9\xf9\xec\xf2\x5f\xa7\xe0} |
118
|
|
|
|
|
|
|
{\x00\x02\x05\x04\x06\x07\x08\x11\x5f\x7f} if defined $msg; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
return $msg; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub ia5_decode { |
125
|
1
|
|
|
1
|
0
|
3
|
my ($self, $msg) = @_; |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
1
|
my $tmp = ""; |
128
|
1
|
|
|
|
|
3
|
my $out = ""; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
4
|
while (length($msg)) { |
131
|
3
|
|
|
|
|
10
|
($tmp,$msg) = ($msg =~ /(..)(.*)/); |
132
|
3
|
|
|
|
|
12
|
$out .= sprintf("%s", chr(hex($tmp))); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
4
|
return $out; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
1
|
0
|
2
|
sub ia5_encode { shift; join('',map {sprintf "%02X", ord} split(//,pop(@_))); } |
|
1
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
10
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub error_by_code { |
141
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
0
|
|
|
0
|
my $ec = shift || ''; |
144
|
0
|
|
|
|
|
0
|
return $self->{EC}->{$ec}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _init { |
148
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
14
|
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
|
|
|
|
|
21
|
$self->{EC} = %ec_string; |
164
|
1
|
|
|
|
|
6
|
$self; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
__END__ |