1 package GSM::SMS::NBS::Message;
3 use GSM::SMS::NBS::Frame;
7 use constant DATAGRAM_LENGTH => 128;
10 # --------------------
11 # This part does the segmentation ... look in Stack.pm for reassembly
15 my $class = ref($proto) || $proto;
18 $self->{'__FRAMES__'} = [];
24 # Create a message from a payload
26 my ($self, $number, $payload, $destination_port, $source_port, $datacodingscheme) = @_;
28 # Reset the FRAME array
29 $#{$self->{'__FRAMES__'}} = -1;
32 my $nbs = GSM::SMS::NBS::Frame->new();
33 my $pdu = GSM::SMS::PDU->new();
35 my $datagram_length = DATAGRAM_LENGTH;
37 $source_port = $destination_port if (!defined($source_port));
39 $dcs = '8bitm' if (defined($destination_port));
41 # print "DATACODINGSCHEME: $datacodingscheme\n";
43 $dcs = $datacodingscheme if (defined($datacodingscheme));
46 $udhi = 0 if (!defined($destination_port));
49 my $payload_len = length($payload)/2;
52 # test if the payload can fit in one message (6= length of minimal header)
53 if (($payload_len + 6) <= 140) {
54 # Ok we can have 1 message
56 $datagram_length = $payload_len;
58 $frags = int($payload_len/$datagram_length) + 1;
61 $nbs->destination_port($destination_port);
62 $nbs->source_port($source_port);
64 # If no destination port defined, then also no source port can be defined
65 # There can be a problem ! what if 2 nbs's send a nbs to the same phone with 2 the same datagrams?
66 # We have to solve this!
67 $nbs->datagram_reference_number(int(rand(255)));
68 $nbs->fragment_maximum($frags);
71 for (my $i=1; $i<=$frags; $i++) {
72 my $subload = substr($payload, ($i-1)*$datagram_length*2, $datagram_length*2);
73 $nbs->fragment_sequence_number($i);
75 if ($destination_port) {
76 $msg = uc $nbs->asString().$subload;
80 # print "DCS-> $dcs\n";
81 my $p = $pdu->SMSSubmit('', $number, $msg, $dcs, '1d', $udhi);
83 # Push on to frame array
84 push(@{$self->{'__FRAMES__'}}, $p );
87 return 0 if ($ok == $frags);
94 return $self->{'__FRAMES__'};
102 GSM::SMS::NBS::Message - SAR functionality for NBS messages.
106 Implements the segmentation in the SAR engine ( Segmentation And Reassembly ).
110 Johan Van den Brande <johan@vandenbrande.com>