blob: 3f6d8cfcc6629d9fd8a5a23907a077eb5edc65cc [file] [log] [blame]
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +08001/* Q.701-Q.704, Q.706, Q.707 handling code */
2/*
3 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010 by On-Waves
5 * All Rights Reserved
6 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +01007 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080010 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010015 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080016 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080019 *
20 */
21
22#ifndef mtp_level3_h
23#define mtp_level3_h
24
Holger Hans Peter Freythercbf7d182010-07-31 05:25:35 +080025#include <stdint.h>
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080026#include <endian.h>
27#include <sys/types.h>
28
29
30/*
31 * pssible service information octets..
32 */
33#define MTP_NI_NATION_NET 0x02
34
35#define MTP_SI_MNT_SNM_MSG 0x00
36#define MTP_SI_MNT_REG_MSG 0x01
37#define MTP_SI_MNT_SCCP 0x03
Holger Hans Peter Freyther3a80cb22010-12-08 11:12:46 +010038#define MTP_SI_MNT_ISUP 0x05
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080039
40/*
41 * h0 contains the group, h1 the semantic of it
42 */
43
44#define MTP_TST_MSG_GRP 0x01
45#define MTP_PROHIBIT_MSG_GRP 0x04
46#define MTP_TRF_RESTR_MSG_GRP 0x07
47
48/* h1 values for different groups */
49#define MTP_TST_MSG_SLTM 0x01
50#define MTP_TST_MSG_SLTA 0x02
51
52#define MTP_RESTR_MSG_ALLWED 0x01
53
54#define MTP_PROHIBIT_MSG_SIG 0x01
55
56
57#define SCCP_SST 0x03
Holger Hans Peter Freyther80ab4c62010-12-31 13:40:19 +010058#define SCCP_SSP 0x02
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080059#define SCCP_SSA 0x01
60
61#define MTP_LINK_MASK 0x0F
62#define MTP_ADDR_MASK 0x0FFF
63#define MTP_APOC_MASK 0x3f
64
65
66#if __BYTE_ORDER == __LITTLE_ENDIAN
67#define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK)
68#define MTP_ADDR(link, dpc, opc) \
69 (((dpc) & MTP_ADDR_MASK) << 0 | \
70 ((opc) & MTP_ADDR_MASK) << 14| \
71 ((link) & MTP_LINK_MASK) << 28)
72#define MTP_MAKE_APOC(apoc) \
73 (apoc & 0x3fff)
74#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther9ed3e1b2010-07-31 05:22:56 +080075static inline uint32_t c_swap_32(uint32_t in)
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080076{
77 return (((in & 0x000000ff) << 24) |
78 ((in & 0x0000ff00) << 8) |
79 ((in & 0x00ff0000) >> 8) |
80 ((in & 0xff000000) >> 24));
81}
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +080082static inline uint16_t c_swap_16(uint16_t in)
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080083{
84 return (((in & 0x00ff) << 8) |
85 (in & 0xff00) >> 8);
86}
87#define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK)
88#define MTP_ADDR(link, dpc, opc) \
89 c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \
90 ((opc) & MTP_ADDR_MASK) << 14| \
91 ((link) & MTP_LINK_MASK) << 28)
92#define MTP_MAKE_APOC(apoc) \
93 c_swap_16((apoc & 0x3fff))
94#endif
95
96
97
98/*
99 * not the on wire address...
100 */
101struct mtp_addr {
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800102 uint16_t dpc;
103 uint16_t opc;
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800104 uint8_t link;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800105} __attribute__((packed));
106
107/*
108 * the struct is defined in Q.704 and can be seen in the
109 * wireshark dissectors too
110 */
111struct mtp_level_3_hdr {
112#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800113 uint8_t ser_ind : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800114 spare : 2,
115 ni : 2;
116#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800117 uint8_t ni : 2,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800118 spare : 2,
119 ser_ind : 4;
120#endif
Holger Hans Peter Freyther9ed3e1b2010-07-31 05:22:56 +0800121 uint32_t addr;
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800122 uint8_t data[0];
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800123} __attribute__((packed));
124
125struct mtp_level_3_cmn {
126#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800127 uint8_t h0 : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800128 h1 : 4;
129#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800130 uint8_t h1 : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800131 h0 : 4;
132#endif
133} __attribute__((packed));
134
135struct mtp_level_3_mng {
136 struct mtp_level_3_cmn cmn;
137#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800138 uint8_t spare : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800139 length : 4;
140#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800141 uint8_t length : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800142 spare : 4;
143#endif
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800144 uint8_t data[0];
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800145} __attribute__((packed));
146
147struct mtp_level_3_prohib {
148 struct mtp_level_3_cmn cmn;
149
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800150 uint16_t apoc;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800151} __attribute__((packed));
152
153struct sccp_con_ctrl_prt_mgt {
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800154 uint8_t sst;
155 uint8_t assn; /* affected sub system number */
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800156 uint16_t apoc;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800157#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800158 uint8_t mul_ind : 2,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800159 spare : 6;
160#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800161 uint8_t spare : 6,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800162 mul_ind : 2;
163#endif
164} __attribute__((packed));
165
166#endif