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