aboutsummaryrefslogtreecommitdiffstats
path: root/GSM411.st
blob: f1f7f1446699728ed61a8fc94a42112439360972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
"
 (C) 2012 by Holger Hans Peter Freyther
 All Rights Reserved

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
"
"Message for GSM04.11"


GSM48DataHolder subclass: GSM411CpUserData [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.1.4.1'>
    <gsmElementId: 2r01>
    <gsmMinValueSize: 0 max: 248>
    <gsmName: 'userData'>
]

GSM48SimpleTag subclass: GSM411CpCause [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.1.4.2'>
    <gsmElementId: 2r10>
    <gsmName: 'cause'>

    GSM411CpCause class [
        causeNetworkFailure                 [ <category: 'cause'> ^ 17 ]
        causeCongestion                     [ <category: 'cause'> ^ 22 ]
        causeInvalidTransaction             [ <category: 'cause'> ^ 81 ]
        causeSemanticallyIncorrectMessage   [ <category: 'cause'> ^ 95 ]
        causeInvalidatMandatoryInformation  [ <category: 'cause'> ^ 96 ]
        causeMessageTypeNonExistent         [ <category: 'cause'> ^ 97 ]
        causeMessageNotCompatible           [ <category: 'cause'> ^ 98 ]
        causeInformationElementNonExistent  [ <category: 'cause'> ^ 99 ]
        causeProtocolError                  [ <category: 'cause'> ^ 111 ]
    ]
]

GSM48SimpleTag subclass: GSM411RpMessageType [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.2'>
]

GSM48FixedSizeIE subclass: GSM411RpMessageReference [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.3'>
    <gsmValueLength: 1>
]

GSM48DataHolder subclass: GSM411RpOriginatorAddress [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.5.1'>
    <gsmMinValueSize: 0 max: 11>
]

GSM48DataHolder subclass: GSM411RpDestinationAddress [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.5.2'>
    <gsmMinValueSize: 0 max: 11>
]

GSM48DataHolder subclass: GSM411RpUserData [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.5.3'>
    <gsmElementId: 2r1000001>
    <gsmMinValueSize: 0 max: 233>
]

GSM48DataHolder subclass: GSM411RpCause [
    <category: 'OsmoGSM-SMS-Types'>
    <comment: '8.2.5.4'>
    <gsmElementId: 2r1000010>
    <gsmMinValueSize: 1 max: 2>

    GSM411RpCause class [
        "MO Causes"
        causeUnassignedNumber                   [ <category: 'cause'> ^ 1 ]
        causeOperatorDeterminedBar              [ <category: 'cause-mo'> ^ 8 ]
        causeCallBarred                         [ <category: 'cause-mo'> ^ 10 ]
        causeReserved                           [ <category: 'cause-mo'> ^ 11 ]
        causeShortMessageTransferRejected       [ <category: 'cause-mo'> ^ 21 ]
        causeDestinationOutOfOrder              [ <category: 'cause-mo'> ^ 27 ]
        causeUnidentifiedSubscriber             [ <category: 'cause-mo'> ^ 28 ]
        causeFacilityRejected                   [ <category: 'cause-mo'> ^ 29 ]
        causeUnknownSubscriber                  [ <category: 'cause-mo'> ^ 30 ]
        causeNetworkOutOfOrder                  [ <category: 'cause-mo'> ^ 38 ]
        causeTemporaryFailure                   [ <category: 'cause-mo'> ^ 41 ]
        causeCongestion                         [ <category: 'cause-mo'> ^ 42 ]
        causeResourcesUnavilable                [ <category: 'cause-mo'> ^ 47 ]
        causeRequestedFacilityNotSubscribed     [ <category: 'cause-mo'> ^ 50 ]
        causeRequestedFacilityNotImplemented    [ <category: 'cause-mo'> ^ 69 ]
        causeInterworkingUnspecified            [ <category: 'cause-mo'> ^ 127 ]

        "MT causes"
        causeMemoryCapacityExceeded             [ <category: 'cause-mt'> ^ 22 ]

        "Common code"
        causeInvalidShortMessageTransferReference   [ <category: 'cause'> ^ 81 ]
        causeSemanticallyIncorrectMessage       [ <category: 'cause'> ^ 95 ]
        causeInvalidatMandatoryInformation      [ <category: 'cause'> ^ 96 ]
        causeMessageTypeNonExistent             [ <category: 'cause'> ^ 97 ]
        causeMessageNotCompatible               [ <category: 'cause'> ^ 98 ]
        causeInformationElementNonExistent      [ <category: 'cause'> ^ 99 ]
        causeProtocolError                      [ <category: 'cause'> ^ 111 ]

        memoryAvailableMessages [
            "Cause names and type for memory available notification"
            ^ OrderedCollection new
                add: #causeUnknownSubscriber    -> #Permanent;
                add: #causeNetworkOutOfOrder    -> #Temporary;
                add: #causeTemporaryFailure     -> #Temporary;
                add: #causeCongestion           -> #Temporary;
                add: #causeResourcesUnavilable  -> #Temporary;
                add: #causeRequestedFacilityNotImplemented  -> #Permanent;
                add: #causeSemanticallyIncorrectMessage -> #Permanent;
                add: #causeInvalidatMandatoryInformation    -> #Permanent;
                add: #causeMessageTypeNonExistent -> #Permanent;
                add: #causeMessageNotCompatible -> #Permanent;
                add: #causeInformationElementNonExistent -> #Permanent;
                add: #causeProtocolError -> #Permanent;
                add: #causeInterworkingUnspecified -> #Permanent;
                yourself
        ]
    ]
]


GSM48MSG subclass: GSMCpMessage [
    <category: 'OsmoGSM-SMS-Message'>

    GSMCpMessage class >> msgCpData [ <category: 'type'> ^ 2r00000001 ]
    GSMCpMessage class >> msgCpAck  [ <category: 'type'> ^ 2r00000100 ]
    GSMCpMessage class >> msgCpError[ <category: 'type'> ^ 2r00010000 ]

    GSMCpMessage class >> isGSMBaseclass [ <category: 'gsm'> ^ self = GSMCpMessage ]
    GSMCpMessage class >> classType [ <category: 'gsm'> ^ 16r9 ]

    ti [
        ^ ti ifNil: [ 0 ]
    ]
]

GSMCpMessage subclass: GSMCpData [
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.2.1'>

    GSMCpData class >> messageType [ <category: 'gsm'> ^ self msgCpData ]
    GSMCpData class >> tlvDescription [
        <category: 'parsing'>
        ^ OrderedCollection new
            add: GSM411CpUserData asTLVDescription;
            yourself
    ]

    rpMessage [
        ^GSMRpMessage decode: self userData data readStream.
    ]
]

GSMCpMessage subclass: GSMCpAck [
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.2.2'>

    GSMCpAck class >> messageType [ <category: 'gsm'> ^ self msgCpAck ]
    GSMCpAck class >> tlvDescription [
        <category: 'parsing'>
        ^ OrderedCollection new
    ]
]

GSMCpMessage subclass: GSMCpError [
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.2.3'>

    GSMCpError class >> messageType [ <category: 'gsm'> ^ self msgCpError ]
    GSMCpError class >> tlvDescription [
        <category: 'parsing'>
        ^ OrderedCollection new
            add: GSM411CpCause asTLVDescription;
            yourself
    ]
]

Object subclass: GSMRpInformationElement [
    <category: 'OsmoGSM-SMS-Message'>

    GSMRpInformationElement class >> readFrom: aStream with: anAttr [
        | len |
        len := aStream next asInteger.
        len printNl.
        ^self new
            readFrom: (aStream next: len);
            yourself.
    ]
]

GSMRpInformationElement subclass: GSMRpOrigantorAddress [
    | data |
    <category: 'OsmoGSM-SMS-Message'>
    GSMRpOrigantorAddress class >> asTLVDescription [
        ^Osmo.TLVDescription new
            beLV; instVarName: #origAddress; parseClass: self;
            yourself.
    ]

    readFrom: anArray [
        data := anArray
    ]

    writeOn: aMessage with: anAttribute [
        aMessage
            putByte: data size;
            putByteArray: data
    ]
]

GSMRpInformationElement subclass: GSMRpDestinationAddress [
    | data |
    <category: 'OsmoGSM-SMS-Message'>
    GSMRpDestinationAddress class >> asTLVDescription [
        ^Osmo.TLVDescription new
            beLV; instVarName: #destAddress; parseClass: self;
            yourself.
    ]

    readFrom: anArray [
        data := anArray
    ]

    writeOn: aMessage with: anAttribute [
        aMessage
            putByte: data size;
            putByteArray: data
    ]
]

GSMRpInformationElement subclass: GSMRpUserData [
    | data |
    <category: 'OsmoGSM-SMS-Message'>
    GSMRpUserData class >> asTLVDescription [
        ^Osmo.TLVDescription new
            beTLV; instVarName: #userData; parseClass: self;
            tag: 16r41; yourself.
    ]

    readFrom: anArray [
        data := anArray
    ]

    writeOn: aMessage with: anAttribute [
        aMessage
            putByte: data size;
            putByteArray: data
    ]
]

Osmo.TLVParserBase subclass: GSMRpMessage [
    | direction reference |
    <category: 'OsmoGSM-SMS-Message'>

    GSMRpMessage class >> decode: aStream [
        <category: '8.2.2'>
        | mti |
        "GSM 04.11 has a crazy table in 8.2.2 for the Message type indicator.
        The decoding depends on the direction but right now it is still unique
        so we can determine direction and and message type from that number."
        mti := (aStream next bitAnd: 2r111).
        mti = 2r000 ifTrue: [^GSMRpData  new decode: aStream direction: #msn].
        mti = 2r001 ifTrue: [^GSMRpData  new decode: aStream direction: #nms].
        mti = 2r010 ifTrue: [^GSMRpAck   new decode: aStream direction: #msn].
        mti = 2r011 ifTrue: [^GSMRpAck   new decode: aStream direction: #nms].
        mti = 2r100 ifTrue: [^GSMRpError new decode: aStream direction: #msn].
        mti = 2r101 ifTrue: [^GSMRpError new decode: aStream direction: #nms].
        mti = 2r110 ifTrue: [^GSMRpSmma  new decode: aStream direction: #msn].
        ^self error: 'Can not decode ', mti displayString.
    ]

    decode: aStream direction: aDirection [
        direction := aDirection.
        reference := aStream next asInteger.

        self class tlvDescription do: [:attr |
            attr isMandatory ifTrue:
                [self doParse: attr stream: aStream].
            attr isOptional ifTrue:
                [self parseOptional: attr tag: aStream peek stream: aStream].
        ].
    ]

    writeHeaderOn: aMessage [
        direction = #msn
            ifTrue: [aMessage putByte: self class messageTypeToNetwork]
            ifFalse: [aMessage putByte: self class messageTypeToMS].
        aMessage putByte: reference.
    ]
]

GSMRpMessage subclass: GSMRpData [
    | origAddress destAddress userData |
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.3.1'>

    GSMRpData class >> messageTypeToNetwork [
        ^2r000
    ]

    GSMRpData class >> messageTypeToMS [
        ^2r001
    ]

    GSMRpData class >> tlvDescription [
        ^OrderedCollection new
            add: GSMRpOrigantorAddress asTLVDescription;
            add: GSMRpDestinationAddress asTLVDescription;
            add: GSMRpUserData asTLVDescription;
            yourself.
    ]
]

GSMRpMessage subclass: GSMRpSmma [
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.3.2'>

    GSMRpSmma class >> tlvDescription [
        ^OrderedCollection new
    ]
]

GSMRpMessage subclass: GSMRpAck [
    | userData |
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.3.3'>

    GSMRpAck class >> tlvDescription [
        ^OrderedCollection new
            add: GSMRpUserData asTLVDescription beOptional yourself;
            yourself.
    ]

    GSMRpAck class >> messageTypeToNetwork [
        ^2r010
    ]
]


GSMRpMessage subclass: GSMRpError [
    | cause userData |
    <category: 'OsmoGSM-SMS-Message'>
    <comment: '7.3.4'>

    GSMRpError class >> tlvDescription [
        ^OrderedCollection new
            add: GSMRpCause asTLVDescription;
            add: GSMRpUserData asTLVDescription beOptional;
            yourself
    ]
]

Eval [
    GSMCpData initialize.
    GSMCpAck initialize.
    GSMCpError initialize.
]