blob: 4b46c080b91016bd3869c562e33c1fba7be6b098 [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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#ifndef mtp_level3_h
24#define mtp_level3_h
25
Holger Hans Peter Freythercbf7d182010-07-31 05:25:35 +080026#include <stdint.h>
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080027#include <endian.h>
28#include <sys/types.h>
29
30
31/*
32 * pssible service information octets..
33 */
34#define MTP_NI_NATION_NET 0x02
35
36#define MTP_SI_MNT_SNM_MSG 0x00
37#define MTP_SI_MNT_REG_MSG 0x01
38#define MTP_SI_MNT_SCCP 0x03
Holger Hans Peter Freyther3a80cb22010-12-08 11:12:46 +010039#define MTP_SI_MNT_ISUP 0x05
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080040
41/*
42 * h0 contains the group, h1 the semantic of it
43 */
44
45#define MTP_TST_MSG_GRP 0x01
46#define MTP_PROHIBIT_MSG_GRP 0x04
47#define MTP_TRF_RESTR_MSG_GRP 0x07
48
49/* h1 values for different groups */
50#define MTP_TST_MSG_SLTM 0x01
51#define MTP_TST_MSG_SLTA 0x02
52
53#define MTP_RESTR_MSG_ALLWED 0x01
54
55#define MTP_PROHIBIT_MSG_SIG 0x01
56
57
58#define SCCP_SST 0x03
Holger Hans Peter Freyther80ab4c62010-12-31 13:40:19 +010059#define SCCP_SSP 0x02
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080060#define SCCP_SSA 0x01
61
62#define MTP_LINK_MASK 0x0F
63#define MTP_ADDR_MASK 0x0FFF
64#define MTP_APOC_MASK 0x3f
65
66
67#if __BYTE_ORDER == __LITTLE_ENDIAN
68#define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK)
69#define MTP_ADDR(link, dpc, opc) \
70 (((dpc) & MTP_ADDR_MASK) << 0 | \
71 ((opc) & MTP_ADDR_MASK) << 14| \
72 ((link) & MTP_LINK_MASK) << 28)
73#define MTP_MAKE_APOC(apoc) \
74 (apoc & 0x3fff)
75#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther9ed3e1b2010-07-31 05:22:56 +080076static inline uint32_t c_swap_32(uint32_t in)
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080077{
78 return (((in & 0x000000ff) << 24) |
79 ((in & 0x0000ff00) << 8) |
80 ((in & 0x00ff0000) >> 8) |
81 ((in & 0xff000000) >> 24));
82}
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +080083static inline uint16_t c_swap_16(uint16_t in)
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080084{
85 return (((in & 0x00ff) << 8) |
86 (in & 0xff00) >> 8);
87}
88#define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK)
89#define MTP_ADDR(link, dpc, opc) \
90 c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \
91 ((opc) & MTP_ADDR_MASK) << 14| \
92 ((link) & MTP_LINK_MASK) << 28)
93#define MTP_MAKE_APOC(apoc) \
94 c_swap_16((apoc & 0x3fff))
95#endif
96
97
98
99/*
100 * not the on wire address...
101 */
102struct mtp_addr {
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800103 uint16_t dpc;
104 uint16_t opc;
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800105 uint8_t link;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800106} __attribute__((packed));
107
108/*
109 * the struct is defined in Q.704 and can be seen in the
110 * wireshark dissectors too
111 */
112struct mtp_level_3_hdr {
113#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800114 uint8_t ser_ind : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800115 spare : 2,
116 ni : 2;
117#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800118 uint8_t ni : 2,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800119 spare : 2,
120 ser_ind : 4;
121#endif
Holger Hans Peter Freyther9ed3e1b2010-07-31 05:22:56 +0800122 uint32_t addr;
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800123 uint8_t data[0];
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800124} __attribute__((packed));
125
126struct mtp_level_3_cmn {
127#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800128 uint8_t h0 : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800129 h1 : 4;
130#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800131 uint8_t h1 : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800132 h0 : 4;
133#endif
134} __attribute__((packed));
135
136struct mtp_level_3_mng {
137 struct mtp_level_3_cmn cmn;
138#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800139 uint8_t spare : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800140 length : 4;
141#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800142 uint8_t length : 4,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800143 spare : 4;
144#endif
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800145 uint8_t data[0];
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800146} __attribute__((packed));
147
148struct mtp_level_3_prohib {
149 struct mtp_level_3_cmn cmn;
150
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800151 uint16_t apoc;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800152} __attribute__((packed));
153
154struct sccp_con_ctrl_prt_mgt {
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800155 uint8_t sst;
156 uint8_t assn; /* affected sub system number */
Holger Hans Peter Freyther585f3d92010-07-31 04:38:17 +0800157 uint16_t apoc;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800158#if __BYTE_ORDER == __LITTLE_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800159 uint8_t mul_ind : 2,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800160 spare : 6;
161#elif __BYTE_ORDER == __BIG_ENDIAN
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800162 uint8_t spare : 6,
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800163 mul_ind : 2;
164#endif
165} __attribute__((packed));
166
167#endif