Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 1 | /* 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 Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame^] | 7 | * 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 Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame^] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 16 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame^] | 17 | * 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 Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifndef mtp_level3_h |
| 23 | #define mtp_level3_h |
| 24 | |
Holger Hans Peter Freyther | cbf7d18 | 2010-07-31 05:25:35 +0800 | [diff] [blame] | 25 | #include <stdint.h> |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 26 | #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 Freyther | 3a80cb2 | 2010-12-08 11:12:46 +0100 | [diff] [blame] | 38 | #define MTP_SI_MNT_ISUP 0x05 |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 39 | |
| 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 Freyther | 80ab4c6 | 2010-12-31 13:40:19 +0100 | [diff] [blame] | 58 | #define SCCP_SSP 0x02 |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 59 | #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 Freyther | 9ed3e1b | 2010-07-31 05:22:56 +0800 | [diff] [blame] | 75 | static inline uint32_t c_swap_32(uint32_t in) |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 76 | { |
| 77 | return (((in & 0x000000ff) << 24) | |
| 78 | ((in & 0x0000ff00) << 8) | |
| 79 | ((in & 0x00ff0000) >> 8) | |
| 80 | ((in & 0xff000000) >> 24)); |
| 81 | } |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 82 | static inline uint16_t c_swap_16(uint16_t in) |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 83 | { |
| 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 | */ |
| 101 | struct mtp_addr { |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 102 | uint16_t dpc; |
| 103 | uint16_t opc; |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 104 | uint8_t link; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 105 | } __attribute__((packed)); |
| 106 | |
| 107 | /* |
| 108 | * the struct is defined in Q.704 and can be seen in the |
| 109 | * wireshark dissectors too |
| 110 | */ |
| 111 | struct mtp_level_3_hdr { |
| 112 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 113 | uint8_t ser_ind : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 114 | spare : 2, |
| 115 | ni : 2; |
| 116 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 117 | uint8_t ni : 2, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 118 | spare : 2, |
| 119 | ser_ind : 4; |
| 120 | #endif |
Holger Hans Peter Freyther | 9ed3e1b | 2010-07-31 05:22:56 +0800 | [diff] [blame] | 121 | uint32_t addr; |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 122 | uint8_t data[0]; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 123 | } __attribute__((packed)); |
| 124 | |
| 125 | struct mtp_level_3_cmn { |
| 126 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 127 | uint8_t h0 : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 128 | h1 : 4; |
| 129 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 130 | uint8_t h1 : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 131 | h0 : 4; |
| 132 | #endif |
| 133 | } __attribute__((packed)); |
| 134 | |
| 135 | struct mtp_level_3_mng { |
| 136 | struct mtp_level_3_cmn cmn; |
| 137 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 138 | uint8_t spare : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 139 | length : 4; |
| 140 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 141 | uint8_t length : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 142 | spare : 4; |
| 143 | #endif |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 144 | uint8_t data[0]; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 145 | } __attribute__((packed)); |
| 146 | |
| 147 | struct mtp_level_3_prohib { |
| 148 | struct mtp_level_3_cmn cmn; |
| 149 | |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 150 | uint16_t apoc; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 151 | } __attribute__((packed)); |
| 152 | |
| 153 | struct sccp_con_ctrl_prt_mgt { |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 154 | uint8_t sst; |
| 155 | uint8_t assn; /* affected sub system number */ |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 156 | uint16_t apoc; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 157 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 158 | uint8_t mul_ind : 2, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 159 | spare : 6; |
| 160 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 161 | uint8_t spare : 6, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 162 | mul_ind : 2; |
| 163 | #endif |
| 164 | } __attribute__((packed)); |
| 165 | |
| 166 | #endif |