631 lines
15 KiB
Smalltalk
631 lines
15 KiB
Smalltalk
Object subclass: SCCPHelper [
|
|
<category: 'osmo-network'>
|
|
SCCPHelper class >> msgCr [ ^ 16r01 ]
|
|
SCCPHelper class >> msgCc [ ^ 16r02 ]
|
|
SCCPHelper class >> msgCref [ ^ 16r03 ]
|
|
SCCPHelper class >> msgRlsd [ ^ 16r04 ]
|
|
SCCPHelper class >> msgRlc [ ^ 16r05 ]
|
|
SCCPHelper class >> msgDt1 [ ^ 16r06 ]
|
|
SCCPHelper class >> msgDt2 [ ^ 16r07 ]
|
|
SCCPHelper class >> msgAk [ ^ 16r08 ]
|
|
SCCPHelper class >> msgUdt [ ^ 16r09 ]
|
|
SCCPHelper class >> msgUdts [ ^ 16r0A ]
|
|
SCCPHelper class >> msgEd [ ^ 16r0B ]
|
|
SCCPHelper class >> msgEa [ ^ 16r0C ]
|
|
SCCPHelper class >> msgRsr [ ^ 16r0D ]
|
|
SCCPHelper class >> msgRsc [ ^ 16r0E ]
|
|
SCCPHelper class >> msgErr [ ^ 16r0F ]
|
|
SCCPHelper class >> msgIt [ ^ 16r10 ]
|
|
SCCPHelper class >> msgXudt [ ^ 16r11 ]
|
|
SCCPHelper class >> msgXudts[ ^ 16r12 ]
|
|
SCCPHelper class >> msgLudt [ ^ 16r13 ]
|
|
SCCPHelper class >> msgLudts[ ^ 16r14 ]
|
|
|
|
SCCPHelper class >> pncData [ ^ 16r0F ]
|
|
SCCPHelper class >> pncEoO [ ^ 16r00 ]
|
|
|
|
SCCPHelper class >> createCR: src dest: dest data: aData [
|
|
^ (SCCPConnectionRequest initWith: src dest: dest data: aData)
|
|
toMessage.
|
|
]
|
|
|
|
SCCPHelper class >> createRLSD: src dest: dest cause: cause [
|
|
^ (SCCPConnectionReleased initWith: src dest: dest cause: cause)
|
|
toMessage.
|
|
]
|
|
|
|
SCCPHelper class >> createDT1: dst data: data [
|
|
^ (SCCPConnectionData initWith: dst data: data)
|
|
toMessage.
|
|
]
|
|
]
|
|
|
|
Object subclass: SCCPPNC [
|
|
| dict |
|
|
|
|
SCCPPNC class >> parseFrom: aPnc [
|
|
| dict pnc |
|
|
|
|
pnc := aPnc.
|
|
dict := Dictionary new.
|
|
|
|
[pnc isEmpty not] whileTrue: [
|
|
| type |
|
|
type := pnc at: 1.
|
|
|
|
type = SCCPHelper pncEoO
|
|
ifTrue: [
|
|
pnc := ByteArray new.
|
|
]
|
|
ifFalse: [
|
|
| size data |
|
|
size := pnc at: 2.
|
|
data := pnc copyFrom: 3 to: 3 + size - 1.
|
|
pnc := pnc copyFrom: 3 + size.
|
|
dict at: type put: data.
|
|
].
|
|
].
|
|
|
|
^ (self new)
|
|
dict: dict;
|
|
yourself.
|
|
]
|
|
|
|
at: aKey put: aValue [
|
|
self dict at: aKey put: aValue.
|
|
]
|
|
|
|
at: aKey [
|
|
^ self dict at: aKey.
|
|
]
|
|
|
|
dict [
|
|
<category: 'accessing'>
|
|
^ dict ifNil: [dict := Dictionary new.]
|
|
]
|
|
|
|
dict: aDict [
|
|
<category: 'private'>
|
|
dict := aDict.
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
self dict keysAndValuesDo: [:key :val |
|
|
| dat |
|
|
dat := val toMessageOrByteArray.
|
|
|
|
aMsg putByte: key.
|
|
aMsg putByte: dat size.
|
|
aMsg putByteArray: dat.
|
|
].
|
|
|
|
aMsg putByte: SCCPHelper pncEoO.
|
|
]
|
|
]
|
|
|
|
Object subclass: SCCPAddress [
|
|
| ssn poi |
|
|
|
|
SCCPAddress class >> createWith: ssn [
|
|
^ (SCCPAddress new)
|
|
ssn: ssn;
|
|
yourself
|
|
]
|
|
|
|
SCCPAddress class >> createWith: ssn poi: aPoi [
|
|
^ SCCPAddress new
|
|
ssn: ssn;
|
|
poi: aPoi;
|
|
yourself
|
|
]
|
|
|
|
SCCPAddress class >> parseFrom: aByteArray [
|
|
| len ai ssn poi dat |
|
|
poi := nil.
|
|
len := aByteArray at: 1.
|
|
ai := aByteArray at: 2.
|
|
|
|
(ai bitAnd: 16r40) = 16r40
|
|
ifFalse: [
|
|
Error signal: 'Address must be routed on SSN'.
|
|
].
|
|
|
|
(ai bitAnd: 16r3C) = 0
|
|
ifFalse: [
|
|
Error signal: 'GlobalTitle indicator must be zero'.
|
|
].
|
|
|
|
dat := aByteArray copyFrom: 3.
|
|
|
|
(ai bitAnd: 1) = 1
|
|
ifTrue: [
|
|
poi := dat at: 1.
|
|
poi := poi bitOr: ((dat at: 2) bitShift: 8).
|
|
dat := dat copyFrom: 3.
|
|
].
|
|
|
|
ssn := dat at: 1.
|
|
^ SCCPAddress createWith: ssn poi: poi.
|
|
]
|
|
|
|
poi: aPoi [
|
|
poi := aPoi.
|
|
]
|
|
|
|
poi [
|
|
^ poi
|
|
]
|
|
|
|
ssn: assn [
|
|
ssn := assn
|
|
]
|
|
|
|
ssn [
|
|
<category: 'accessing'>
|
|
^ ssn.
|
|
]
|
|
|
|
asByteArray [
|
|
"Most simple address storing routine"
|
|
| ai data |
|
|
|
|
data := OrderedCollection new.
|
|
|
|
"Create the Address Information"
|
|
ai := 0.
|
|
ai := ai bitOr: 2.
|
|
ai := ai bitOr: 64.
|
|
|
|
poi ifNotNil: [
|
|
ai := ai bitOr: 1.
|
|
].
|
|
|
|
data add: ai.
|
|
|
|
"Now write the data in the right order"
|
|
poi ifNotNil: [
|
|
data add: ((poi bitAnd: 16r00FF) bitShift: 0).
|
|
data add: ((poi bitAnd: 16rFF00) bitShift: -8).
|
|
].
|
|
|
|
data add: ssn.
|
|
data addFirst: data size.
|
|
|
|
^ data asByteArray
|
|
]
|
|
]
|
|
|
|
Object subclass: SCCPAddrReference [
|
|
<category: 'osmo-network'>
|
|
SCCPAddrReference class >> store: anAddress on: aMsg [
|
|
"Store the threee bytes of an sccp address on a messagebuffer"
|
|
|
|
aMsg putByte: ((anAddress bitAnd: 16r000000FF) bitShift: -0).
|
|
aMsg putByte: ((anAddress bitAnd: 16r0000FF00) bitShift: -8).
|
|
aMsg putByte: ((anAddress bitAnd: 16r00FF0000) bitShift: -16).
|
|
]
|
|
|
|
SCCPAddrReference class >> fromCData: anArray [
|
|
"Parse from an CArray"
|
|
|
|
| oct1 oct2 oct3 |
|
|
oct1 := (anArray at: 0) bitShift: 0.
|
|
oct2 := (anArray at: 1) bitShift: 8.
|
|
oct3 := (anArray at: 2) bitShift: 16.
|
|
|
|
^ (oct1 bitOr: oct2) bitOr: oct3
|
|
]
|
|
|
|
SCCPAddrReference class >> fromByteArray: anArray [
|
|
"Parse from a ByteArray"
|
|
| oct1 oct2 oct3 |
|
|
oct1 := (anArray at: 1) bitShift: 0.
|
|
oct2 := (anArray at: 2) bitShift: 8.
|
|
oct3 := (anArray at: 3) bitShift: 16.
|
|
|
|
^ (oct1 bitOr: oct2) bitOr: oct3
|
|
]
|
|
]
|
|
|
|
Object subclass: SCCPMessage [
|
|
SCCPMessage class >> decode: aByteArray [
|
|
| type |
|
|
type := aByteArray at: 1.
|
|
|
|
SCCPMessage allSubclassesDo: [:each |
|
|
each msgType = type
|
|
ifTrue: [
|
|
^ each parseFrom: aByteArray.
|
|
]
|
|
].
|
|
|
|
"raise exception"
|
|
^ Error signal: 'No handler for: ', type asString.
|
|
]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPConnectionRequest [
|
|
<category: 'osmo-network'>
|
|
| src dst pnc |
|
|
|
|
SCCPConnectionRequest class >> msgType [
|
|
<category: 'factory'>
|
|
^ SCCPHelper msgCr
|
|
]
|
|
|
|
SCCPConnectionRequest class >> initWith: src dest: dest pnc: pnc [
|
|
<category: 'construction'>
|
|
^ self new
|
|
src: src dest: dest pnc: pnc;
|
|
yourself
|
|
]
|
|
|
|
SCCPConnectionRequest class >> initWith: src dest: dest data: data [
|
|
<category: 'construction'>
|
|
| pnc |
|
|
pnc := SCCPPNC new.
|
|
pnc at: SCCPHelper pncData put: data.
|
|
|
|
^ self new
|
|
src: src dest: dest pnc: pnc;
|
|
yourself
|
|
]
|
|
|
|
SCCPConnectionRequest class >> parseFrom: aMsg [
|
|
| src addr proto variable optional pnc |
|
|
src := SCCPAddrReference fromByteArray: (aMsg copyFrom: 2 to: 4).
|
|
proto := (aMsg at: 5) asInteger.
|
|
variable := (aMsg at: 6) asInteger.
|
|
optional := (aMsg at: 7) asInteger.
|
|
|
|
"some sanity check"
|
|
proto ~= 2 ifTrue: [
|
|
Exception signal: 'Proto should be two was ', proto asString.
|
|
].
|
|
|
|
"parse the address"
|
|
addr := SCCPAddress parseFrom: (aMsg copyFrom: (6 + variable)).
|
|
|
|
"parse the optional data"
|
|
pnc := SCCPPNC parseFrom: (aMsg copyFrom: (7 + optional)).
|
|
|
|
^ SCCPConnectionRequest initWith: src dest: addr pnc: pnc.
|
|
]
|
|
|
|
src [
|
|
<category: 'accessing'>
|
|
^ src
|
|
]
|
|
|
|
dest [
|
|
<category: 'accessing'>
|
|
^ dst
|
|
]
|
|
|
|
data [
|
|
<category: 'accessing'>
|
|
^ pnc at: SCCPHelper pncData.
|
|
]
|
|
|
|
data: aData [
|
|
pnc at: SCCPHelper pncData put: aData.
|
|
]
|
|
|
|
src: aSrc dest: aDest pnc: aPnc [
|
|
src := aSrc.
|
|
dst := aDest.
|
|
pnc := aPnc.
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
<category: 'conversion'>
|
|
| dat len addr |
|
|
|
|
addr := dst asByteArray.
|
|
|
|
aMsg putByte: self class msgType.
|
|
SCCPAddrReference store: src on: aMsg.
|
|
"store proto_class, variable_called, optional_start"
|
|
aMsg putByte: 2.
|
|
aMsg putByte: 2.
|
|
aMsg putByte: 1 + addr size.
|
|
|
|
aMsg putByteArray: addr.
|
|
|
|
" place the data now "
|
|
pnc writeOn: aMsg.
|
|
^ aMsg.
|
|
]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPConnectionConfirm [
|
|
| src dst pnc |
|
|
SCCPConnectionConfirm class >> msgType [
|
|
<category: 'factory'>
|
|
^ SCCPHelper msgCc
|
|
]
|
|
|
|
SCCPConnectionConfirm class >> initWithSrc: aSrc dst: aDst [
|
|
^ self new
|
|
src: aSrc dst: aDst;
|
|
yourself
|
|
]
|
|
|
|
SCCPConnectionConfirm class >> parseFrom: aMsg [
|
|
| src dst proto optional |
|
|
dst := SCCPAddrReference fromByteArray: (aMsg copyFrom: 2 to: 4).
|
|
src := SCCPAddrReference fromByteArray: (aMsg copyFrom: 5 to: 7).
|
|
proto := aMsg at: 8.
|
|
optional := aMsg at: 9.
|
|
|
|
"TODO: Add additional items"
|
|
^ self new
|
|
src: src dst: dst;
|
|
yourself
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
<category: 'conversion'>
|
|
|
|
aMsg putByte: SCCPHelper msgCc.
|
|
SCCPAddrReference store: dst on: aMsg.
|
|
SCCPAddrReference store: src on: aMsg.
|
|
aMsg putByte: 2.
|
|
aMsg putByte: 1.
|
|
self pnc writeOn: aMsg.
|
|
]
|
|
|
|
src: aSrc dst: aDst [
|
|
src := aSrc.
|
|
dst := aDst.
|
|
]
|
|
|
|
src [ ^ src ]
|
|
dst [ ^ dst ]
|
|
pnc [ ^ pnc ifNil: [ pnc := SCCPPNC new. ] ]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPConnectionReleased [
|
|
<category: 'osmo-network'>
|
|
| src dst cause |
|
|
|
|
SCCPConnectionReleased class >> msgType [
|
|
<category: 'factory'>
|
|
^ SCCPHelper msgRlsd
|
|
]
|
|
|
|
SCCPConnectionReleased class >> initWith: src dest: dest cause: cause [
|
|
<category: 'construction'>
|
|
^ self new
|
|
src: src;
|
|
dst: dest;
|
|
cause: cause;
|
|
yourself
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
<category: 'conversion'>
|
|
|
|
aMsg putByte: self class msgType.
|
|
SCCPAddrReference store: dst on: aMsg.
|
|
SCCPAddrReference store: src on: aMsg.
|
|
aMsg putByte: cause.
|
|
aMsg putByte: 1.
|
|
aMsg putByte: SCCPHelper pncEoO.
|
|
|
|
^ aMsg.
|
|
]
|
|
|
|
|
|
src: aSrc [
|
|
src := aSrc.
|
|
]
|
|
|
|
dst: aDst [
|
|
dst := aDst.
|
|
]
|
|
|
|
cause: aCause [
|
|
cause := aCause.
|
|
]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPConnectionData [
|
|
| dst data |
|
|
|
|
SCCPConnectionData class >> msgType [
|
|
<category: 'factory'>
|
|
^ SCCPHelper msgDt1
|
|
]
|
|
|
|
SCCPConnectionData class >> initWith: dst data: data [
|
|
^ (self new)
|
|
dst: dst;
|
|
data: data;
|
|
yourself.
|
|
]
|
|
|
|
SCCPConnectionData class >> parseFrom: aByteArray [
|
|
| more_data var_start addr size data |
|
|
addr := SCCPAddrReference fromByteArray: (aByteArray copyFrom: 2).
|
|
more_data := aByteArray at: 5.
|
|
more_data = 0 ifFalse: [
|
|
Error signal: 'Fragmented data is not supported.'.
|
|
].
|
|
|
|
var_start := aByteArray at: 6.
|
|
size := aByteArray at: 6 + var_start.
|
|
data := aByteArray copyFrom: (6 + var_start + 1) to: (6 + var_start + size).
|
|
|
|
^ SCCPConnectionData initWith: addr data: data.
|
|
]
|
|
|
|
dst: aDst [
|
|
<category: 'private'>
|
|
dst := aDst.
|
|
]
|
|
|
|
data: aData [
|
|
<category: 'private'>
|
|
data := aData.
|
|
|
|
data size > 16rFF ifTrue: [
|
|
self error: 'Data must be < 256 in size.'
|
|
].
|
|
]
|
|
|
|
dst [
|
|
^ dst
|
|
]
|
|
|
|
data [
|
|
^ data
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
| dat |
|
|
<category: 'conversion'>
|
|
|
|
aMsg putByte: self class msgType.
|
|
SCCPAddrReference store: dst on: aMsg.
|
|
aMsg putByte: 0.
|
|
aMsg putByte: 1.
|
|
|
|
dat := data toMessageOrByteArray.
|
|
aMsg putByte: dat size.
|
|
aMsg putByteArray: dat.
|
|
|
|
^ aMsg
|
|
]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPConnectionReleased [
|
|
| src dst cause pnc |
|
|
|
|
SCCPConnectionReleased class >> msgType [
|
|
<category: 'factory'>
|
|
^ SCCPHelper msgRlsd
|
|
]
|
|
|
|
SCCPConnectionReleased class >> initWithDst: aDst src: aSrc cause: aCause [
|
|
^ self new
|
|
dst: aDst;
|
|
src: aSrc;
|
|
cause: aCause;
|
|
yourself.
|
|
]
|
|
|
|
SCCPConnectionReleased class >> parseFrom: aByteArray [
|
|
| dst src cause |
|
|
|
|
dst := SCCPAddrReference fromByteArray: (aByteArray copyFrom: 2).
|
|
src := SCCPAddrReference fromByteArray: (aByteArray copyFrom: 5).
|
|
cause := aByteArray at: 8.
|
|
|
|
^ SCCPConnectionReleased initWithDst: dst src: src cause: cause.
|
|
]
|
|
|
|
dst [ ^ dst ]
|
|
src [ ^ src ]
|
|
cause [ ^ cause ]
|
|
dst: aDst [ dst := aDst ]
|
|
src: aSrc [ src := aSrc ]
|
|
cause: aCause [ cause := aCause ]
|
|
|
|
pnc [
|
|
^ pnc ifNil: [pnc := SCCPPNC new]
|
|
]
|
|
|
|
|
|
writeOn: aMsg [
|
|
aMsg putByte: self class msgType.
|
|
SCCPAddrReference store: dst on: aMsg.
|
|
SCCPAddrReference store: src on: aMsg.
|
|
aMsg putByte: cause.
|
|
aMsg putByte: 1.
|
|
self pnc writeOn: aMsg.
|
|
]
|
|
]
|
|
|
|
SCCPMessage subclass: SCCPUDT [
|
|
| called calling data |
|
|
|
|
SCCPUDT class >> msgType [
|
|
^ SCCPHelper msgUdt
|
|
]
|
|
|
|
SCCPUDT class >> initWith: aCalled calling: aCalling data: aData [
|
|
^ self new
|
|
calledAddr: aCalled;
|
|
callingAddr: aCalling;
|
|
data: aData;
|
|
yourself
|
|
]
|
|
|
|
SCCPUDT class >> parseFrom: aByteArray [
|
|
| called calledData calling callingData data dataData dataSize |
|
|
(aByteArray at: 2) = 0
|
|
ifFalse: [
|
|
Error signal: 'Can only handle simple UDT messages.'.
|
|
].
|
|
|
|
called := aByteArray at: 3.
|
|
calledData := aByteArray copyFrom: (3 + called).
|
|
|
|
calling := aByteArray at: 4.
|
|
callingData := aByteArray copyFrom: (4 + calling).
|
|
|
|
data := aByteArray at: 5.
|
|
dataSize := aByteArray at: (5 + data).
|
|
dataData := aByteArray copyFrom: (6 + data) to: 5 + data + dataSize.
|
|
|
|
^ SCCPUDT initWith: (SCCPAddress parseFrom: calledData)
|
|
calling: (SCCPAddress parseFrom: callingData)
|
|
data: dataData.
|
|
]
|
|
|
|
calledAddr: aCalled [
|
|
called := aCalled
|
|
]
|
|
|
|
calledAddr [
|
|
^ called
|
|
]
|
|
|
|
callingAddr: aCalling [
|
|
calling := aCalling
|
|
]
|
|
|
|
callingAddr [
|
|
^ calling
|
|
]
|
|
|
|
data [
|
|
^ data
|
|
]
|
|
|
|
data: aData [
|
|
data := aData.
|
|
]
|
|
|
|
writeOn: aMsg [
|
|
| calledData callingData |
|
|
calledData := called asByteArray.
|
|
callingData := calling asByteArray.
|
|
|
|
aMsg putByte: self class msgType.
|
|
aMsg putByte: 0.
|
|
|
|
"pointers"
|
|
aMsg putByte: 3.
|
|
aMsg putByte: 1 + calledData size + 1.
|
|
aMsg putByte: calledData size + callingData size + 1.
|
|
|
|
"the data"
|
|
aMsg putByteArray: calledData.
|
|
aMsg putByteArray: callingData.
|
|
aMsg putByte: data size.
|
|
aMsg putByteArray: data.
|
|
]
|
|
]
|