-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsccp.go
102 lines (93 loc) · 2.29 KB
/
sccp.go
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
// Copyright 2019-2024 go-sccp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
/*
Package sccp provides encoding/decoding feature of Signalling Connection Control Part used in SS7/SIGTRAN protocol stack.
This is still an experimental project, and currently in its very early stage of development. Any part of implementations
(including exported APIs) may be changed before released as v1.0.0.
*/
package sccp
import (
"encoding"
"fmt"
"io"
)
// MsgType is type of SCCP message.
type MsgType uint8
// Message Type definitions.
const (
_ MsgType = iota
MsgTypeCR // CR
MsgTypeCC // CC
MsgTypeCREF // CREF
MsgTypeRLSD // RLSD
MsgTypeRLC // RLC
MsgTypeDT1 // DT1
MsgTypeDT2 // DT2
MsgTypeAK // AK
MsgTypeUDT // UDT
MsgTypeUDTS // UDTS
MsgTypeED // ED
MsgTypeEA // EA
MsgTypeRSR // RSR
MsgTypeRSC // RSC
MsgTypeERR // ERR
MsgTypeIT // IT
MsgTypeXUDT // XUDT
MsgTypeXUDTS // XUDTS
MsgTypeLUDT // LUDT
MsgTypeLUDTS // LUDTS
)
// Message is an interface that defines SCCP messages.
type Message interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
MarshalTo([]byte) error
MarshalLen() int
MessageType() MsgType
MessageTypeName() string
fmt.Stringer
}
// ParseMessage decodes the byte sequence into Message by Message Type.
func ParseMessage(b []byte) (Message, error) {
if len(b) < 1 {
return nil, fmt.Errorf("invalid SCCP message %v: %w", b, io.ErrUnexpectedEOF)
}
var m Message
switch MsgType(b[0]) {
/* TODO: implement!
case MsgTypeCR:
case MsgTypeCC:
case MsgTypeCREF:
case MsgTypeRLSD:
case MsgTypeRLC:
case MsgTypeDT1:
case MsgTypeDT2:
case MsgTypeAK:
*/
case MsgTypeUDT:
m = &UDT{}
/* TODO: implement!
case MsgTypeUDTS:
case MsgTypeED:
case MsgTypeEA:
case MsgTypeRSR:
case MsgTypeRSC:
case MsgTypeERR:
case MsgTypeIT:
*/
case MsgTypeXUDT:
m = &XUDT{}
/* TODO: implement!
case MsgTypeXUDTS:
case MsgTypeLUDT:
case MsgTypeLUDTS:
*/
default:
return nil, UnsupportedTypeError(b[0])
}
if err := m.UnmarshalBinary(b); err != nil {
return nil, err
}
return m, nil
}