2010-11-14 21:43:29 +00:00
|
|
|
PackageLoader fileInPackage: 'OsmoNetwork'.
|
|
|
|
|
2010-11-20 08:35:12 +00:00
|
|
|
Object subclass: SCCPConnection [
|
2010-11-28 20:14:25 +00:00
|
|
|
| src dst queue handler confirmSem proc |
|
|
|
|
|
|
|
|
SCCPConnection class >> new [
|
|
|
|
^ super new
|
|
|
|
initialize; yourself
|
|
|
|
]
|
|
|
|
|
|
|
|
initialize [
|
|
|
|
confirmSem := Semaphore new.
|
|
|
|
]
|
|
|
|
|
|
|
|
handler: aHandler [
|
|
|
|
<category: 'private'>
|
|
|
|
handler := aHandler.
|
|
|
|
]
|
2010-11-20 08:35:12 +00:00
|
|
|
|
|
|
|
srcRef [
|
2010-11-28 20:14:25 +00:00
|
|
|
<category: 'access'>
|
2010-11-20 08:35:12 +00:00
|
|
|
^ src
|
|
|
|
]
|
|
|
|
srcRef: aRef [
|
2010-11-28 20:14:25 +00:00
|
|
|
<category: 'access'>
|
2010-11-20 08:35:12 +00:00
|
|
|
src := aRef
|
|
|
|
]
|
|
|
|
|
|
|
|
dstRef: aRef [
|
2010-11-28 20:14:25 +00:00
|
|
|
<category: 'access'>
|
2010-11-20 08:35:12 +00:00
|
|
|
dst := aRef
|
|
|
|
]
|
2010-11-22 16:16:44 +00:00
|
|
|
|
2010-11-28 09:14:15 +00:00
|
|
|
dstRef [
|
2010-11-28 20:14:25 +00:00
|
|
|
<category: 'access'>
|
2010-11-28 09:14:15 +00:00
|
|
|
^ dst
|
|
|
|
]
|
|
|
|
|
2010-11-22 16:16:44 +00:00
|
|
|
readQueue [
|
|
|
|
^ queue ifNil: [ queue := SharedQueue new. ]
|
|
|
|
]
|
2010-11-28 09:44:50 +00:00
|
|
|
|
2010-11-28 20:14:25 +00:00
|
|
|
cleanUp [
|
|
|
|
"I get called at the end of a SCCP connection"
|
|
|
|
<category: 'connection-handling'>
|
|
|
|
|
|
|
|
('Cleaningup the SCCP connection: ', dst asString) printNl.
|
|
|
|
|
|
|
|
handler := nil.
|
|
|
|
queue := nil.
|
|
|
|
proc := nil.
|
|
|
|
]
|
|
|
|
|
|
|
|
handleMessages [
|
|
|
|
proc := [
|
|
|
|
[
|
|
|
|
self waitForConfirmation.
|
|
|
|
'SCCP Connection Confirmed' printNl.
|
|
|
|
|
|
|
|
[true] whileTrue: [
|
|
|
|
| msg |
|
|
|
|
|
|
|
|
msg := self readQueue next.
|
|
|
|
msg inspect.
|
|
|
|
].
|
|
|
|
] ensure: [
|
|
|
|
"An exception? an error?"
|
|
|
|
self cleanUp.
|
|
|
|
]
|
|
|
|
] fork.
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
waitForConfirmation [
|
|
|
|
"TODO: Add timeout handling"
|
|
|
|
confirmSem wait
|
|
|
|
]
|
|
|
|
|
2010-11-28 09:44:50 +00:00
|
|
|
confirm: aCC [
|
|
|
|
<category: 'connection-handling'>
|
2010-11-28 20:14:25 +00:00
|
|
|
self dstRef: aCC src.
|
|
|
|
confirmSem signal.
|
2010-11-28 09:44:50 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
data: aDT [
|
2010-11-28 20:14:25 +00:00
|
|
|
self readQueue nextPut: aDT data.
|
2010-11-28 09:44:50 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
released: aRLSD [
|
2010-11-28 20:14:25 +00:00
|
|
|
| rlc |
|
2010-11-28 09:44:50 +00:00
|
|
|
"Give up local resources here. We are done."
|
2010-11-28 20:14:25 +00:00
|
|
|
|
|
|
|
rlc := Osmo.SCCPConnectionReleaseComplete
|
|
|
|
initWithDst: aRLSD src src: aRLSD dst.
|
|
|
|
self sendMsg: rlc toMessage.
|
|
|
|
|
|
|
|
proc ifNotNil: [
|
|
|
|
proc terminate.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
sendMsg: aMsg [
|
|
|
|
handler sendMsg: aMsg.
|
2010-11-28 09:44:50 +00:00
|
|
|
]
|
2010-11-20 08:35:12 +00:00
|
|
|
]
|
|
|
|
|
2010-11-22 16:13:26 +00:00
|
|
|
Object subclass: MSGParser [
|
|
|
|
<comment: 'I take a SCCP message and recursively parse all the data'>
|
|
|
|
|
|
|
|
MSGParser class >> parse: aByteArray [
|
|
|
|
| sccp |
|
|
|
|
"Return a completely decoded subtree"
|
|
|
|
|
|
|
|
sccp := Osmo.SCCPMessage decode: aByteArray.
|
|
|
|
(sccp respondsTo: #data)
|
|
|
|
ifTrue: [
|
|
|
|
sccp data: (self decodeBSSAP: sccp data).
|
|
|
|
].
|
|
|
|
|
|
|
|
^ sccp
|
|
|
|
]
|
|
|
|
|
|
|
|
MSGParser class >> decodeBSSAP: aData [
|
|
|
|
| bssap |
|
|
|
|
bssap := BSSAPMessage decode: aData.
|
2010-11-24 14:17:10 +00:00
|
|
|
bssap class msgType = BSSAPDTAP msgType
|
2010-11-22 16:13:26 +00:00
|
|
|
ifTrue: [
|
2010-11-24 14:17:10 +00:00
|
|
|
bssap data: (GSM48MSG decode: bssap data)
|
|
|
|
]
|
|
|
|
ifFalse: [
|
2010-11-22 16:13:26 +00:00
|
|
|
bssap data: (self decodeBSSMAP: bssap data).
|
2010-11-24 14:17:10 +00:00
|
|
|
].
|
2010-11-22 16:13:26 +00:00
|
|
|
|
|
|
|
^ bssap
|
|
|
|
]
|
|
|
|
|
|
|
|
MSGParser class >> decodeBSSMAP: aData [
|
|
|
|
| bssmap |
|
|
|
|
bssmap := IEMessage decode: aData with: GSM0808IE.
|
2010-11-23 23:41:38 +00:00
|
|
|
bssmap findIE: (GSMLayer3Info elementId) ifPresent: [:each |
|
|
|
|
each data: (GSM48MSG decode: each data).
|
|
|
|
].
|
2010-11-22 16:13:26 +00:00
|
|
|
^ bssmap
|
|
|
|
]
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2010-11-24 09:58:30 +00:00
|
|
|
Object subclass: SCCPHandler [
|
2010-11-28 20:14:25 +00:00
|
|
|
| connections last_ref connection |
|
2010-11-14 21:43:29 +00:00
|
|
|
<comment: 'I handle SCCP messages'>
|
|
|
|
|
|
|
|
registerOn: aDispatcher [
|
|
|
|
aDispatcher addHandler: Osmo.IPAConstants protocolSCCP
|
2010-11-15 15:26:00 +00:00
|
|
|
on: self with: #handleMsg:.
|
2010-11-14 21:43:29 +00:00
|
|
|
]
|
|
|
|
|
2010-11-28 09:44:50 +00:00
|
|
|
forwardMessage: aMessage with: aConnection[
|
|
|
|
(aMessage isKindOf: Osmo.SCCPConnectionConfirm)
|
|
|
|
ifTrue: [
|
|
|
|
aConnection confirm: aMessage.
|
|
|
|
^ true
|
|
|
|
].
|
|
|
|
(aMessage isKindOf: Osmo.SCCPConnectionData)
|
|
|
|
ifTrue: [
|
|
|
|
aConnection data: aMessage.
|
|
|
|
^ true
|
|
|
|
].
|
|
|
|
(aMessage isKindOf: Osmo.SCCPConnectionReleased)
|
|
|
|
ifTrue: [
|
|
|
|
aConnection released: aMessage.
|
|
|
|
self connections remove: aConnection.
|
|
|
|
^ true
|
|
|
|
].
|
|
|
|
|
|
|
|
"Message is not handled here"
|
|
|
|
^ false
|
|
|
|
]
|
2010-11-28 09:14:15 +00:00
|
|
|
|
2010-11-28 09:44:50 +00:00
|
|
|
dispatchMessage: aMessage [
|
|
|
|
self connections do: [:each |
|
|
|
|
each srcRef = aMessage dst
|
2010-11-28 09:14:15 +00:00
|
|
|
ifTrue: [
|
2010-11-28 09:44:50 +00:00
|
|
|
^ self forwardMessage: aMessage with: each.
|
2010-11-28 09:14:15 +00:00
|
|
|
].
|
2010-11-28 09:44:50 +00:00
|
|
|
].
|
|
|
|
|
|
|
|
'No one has handled the connection with ', aMessage dst asString printNl.
|
2010-11-28 09:14:15 +00:00
|
|
|
]
|
|
|
|
|
2010-11-15 15:26:00 +00:00
|
|
|
handleMsg: aMsg [
|
2010-11-24 09:58:30 +00:00
|
|
|
| sccp |
|
|
|
|
|
|
|
|
[
|
|
|
|
sccp := MSGParser parse: (aMsg asByteArray).
|
|
|
|
] on: Exception do: [
|
|
|
|
self logError: 'Failed to parse message' area: #sccp.
|
|
|
|
aMsg asByteArray printNl.
|
2010-11-28 09:14:15 +00:00
|
|
|
^ false
|
|
|
|
].
|
|
|
|
|
2010-11-28 09:44:50 +00:00
|
|
|
self dispatchMessage: sccp.
|
2010-11-14 21:43:29 +00:00
|
|
|
]
|
2010-11-20 08:35:12 +00:00
|
|
|
|
2010-11-28 20:14:25 +00:00
|
|
|
|
|
|
|
connection: aConnection [
|
|
|
|
connection := aConnection.
|
|
|
|
]
|
|
|
|
|
|
|
|
sendMsg: aMsg [
|
|
|
|
"Send a SCCP message."
|
|
|
|
connection send: aMsg with: Osmo.IPAConstants protocolSCCP.
|
|
|
|
]
|
|
|
|
|
2010-11-20 08:35:12 +00:00
|
|
|
createConnection: aData [
|
|
|
|
| con res|
|
|
|
|
|
|
|
|
con := SCCPConnection new.
|
|
|
|
con srcRef: self assignSrcRef.
|
2010-11-28 20:14:25 +00:00
|
|
|
con handler: self.
|
2010-11-20 08:35:12 +00:00
|
|
|
res := Osmo.SCCPConnectionRequest
|
|
|
|
initWith: (con srcRef) dest: (Osmo.SCCPAddress createWith: 254) data: aData.
|
2010-11-28 09:13:10 +00:00
|
|
|
self connections add: con.
|
2010-11-28 20:14:25 +00:00
|
|
|
con handleMessages.
|
2010-11-20 08:35:12 +00:00
|
|
|
|
|
|
|
^ res
|
|
|
|
]
|
|
|
|
|
|
|
|
assignSrcRef [
|
|
|
|
^ 666
|
|
|
|
]
|
|
|
|
|
|
|
|
connections [
|
|
|
|
^ connections ifNil: [ connections := OrderedCollection new. ]
|
|
|
|
]
|
2010-11-14 21:43:29 +00:00
|
|
|
]
|
|
|
|
|