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 | |
| 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 |
| 38 | |
| 39 | /* |
| 40 | * h0 contains the group, h1 the semantic of it |
| 41 | */ |
| 42 | |
| 43 | #define MTP_TST_MSG_GRP 0x01 |
| 44 | #define MTP_PROHIBIT_MSG_GRP 0x04 |
| 45 | #define MTP_TRF_RESTR_MSG_GRP 0x07 |
| 46 | |
| 47 | /* h1 values for different groups */ |
| 48 | #define MTP_TST_MSG_SLTM 0x01 |
| 49 | #define MTP_TST_MSG_SLTA 0x02 |
| 50 | |
| 51 | #define MTP_RESTR_MSG_ALLWED 0x01 |
| 52 | |
| 53 | #define MTP_PROHIBIT_MSG_SIG 0x01 |
| 54 | |
| 55 | |
| 56 | #define SCCP_SST 0x03 |
| 57 | #define SCCP_SSA 0x01 |
| 58 | |
| 59 | #define MTP_LINK_MASK 0x0F |
| 60 | #define MTP_ADDR_MASK 0x0FFF |
| 61 | #define MTP_APOC_MASK 0x3f |
| 62 | |
| 63 | |
| 64 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 65 | #define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK) |
| 66 | #define MTP_ADDR(link, dpc, opc) \ |
| 67 | (((dpc) & MTP_ADDR_MASK) << 0 | \ |
| 68 | ((opc) & MTP_ADDR_MASK) << 14| \ |
| 69 | ((link) & MTP_LINK_MASK) << 28) |
| 70 | #define MTP_MAKE_APOC(apoc) \ |
| 71 | (apoc & 0x3fff) |
| 72 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 9ed3e1b | 2010-07-31 05:22:56 +0800 | [diff] [blame^] | 73 | static inline uint32_t c_swap_32(uint32_t in) |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 74 | { |
| 75 | return (((in & 0x000000ff) << 24) | |
| 76 | ((in & 0x0000ff00) << 8) | |
| 77 | ((in & 0x00ff0000) >> 8) | |
| 78 | ((in & 0xff000000) >> 24)); |
| 79 | } |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 80 | static inline uint16_t c_swap_16(uint16_t in) |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 81 | { |
| 82 | return (((in & 0x00ff) << 8) | |
| 83 | (in & 0xff00) >> 8); |
| 84 | } |
| 85 | #define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK) |
| 86 | #define MTP_ADDR(link, dpc, opc) \ |
| 87 | c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \ |
| 88 | ((opc) & MTP_ADDR_MASK) << 14| \ |
| 89 | ((link) & MTP_LINK_MASK) << 28) |
| 90 | #define MTP_MAKE_APOC(apoc) \ |
| 91 | c_swap_16((apoc & 0x3fff)) |
| 92 | #endif |
| 93 | |
| 94 | |
| 95 | |
| 96 | /* |
| 97 | * not the on wire address... |
| 98 | */ |
| 99 | struct mtp_addr { |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 100 | uint16_t dpc; |
| 101 | uint16_t opc; |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 102 | uint8_t link; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 103 | } __attribute__((packed)); |
| 104 | |
| 105 | /* |
| 106 | * the struct is defined in Q.704 and can be seen in the |
| 107 | * wireshark dissectors too |
| 108 | */ |
| 109 | struct mtp_level_3_hdr { |
| 110 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 111 | uint8_t ser_ind : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 112 | spare : 2, |
| 113 | ni : 2; |
| 114 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 115 | uint8_t ni : 2, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 116 | spare : 2, |
| 117 | ser_ind : 4; |
| 118 | #endif |
Holger Hans Peter Freyther | 9ed3e1b | 2010-07-31 05:22:56 +0800 | [diff] [blame^] | 119 | uint32_t addr; |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 120 | uint8_t data[0]; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 121 | } __attribute__((packed)); |
| 122 | |
| 123 | struct mtp_level_3_cmn { |
| 124 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 125 | uint8_t h0 : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 126 | h1 : 4; |
| 127 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 128 | uint8_t h1 : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 129 | h0 : 4; |
| 130 | #endif |
| 131 | } __attribute__((packed)); |
| 132 | |
| 133 | struct mtp_level_3_mng { |
| 134 | struct mtp_level_3_cmn cmn; |
| 135 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 136 | uint8_t spare : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 137 | length : 4; |
| 138 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 139 | uint8_t length : 4, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 140 | spare : 4; |
| 141 | #endif |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 142 | uint8_t data[0]; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 143 | } __attribute__((packed)); |
| 144 | |
| 145 | struct mtp_level_3_prohib { |
| 146 | struct mtp_level_3_cmn cmn; |
| 147 | |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 148 | uint16_t apoc; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 149 | } __attribute__((packed)); |
| 150 | |
| 151 | struct sccp_con_ctrl_prt_mgt { |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 152 | uint8_t sst; |
| 153 | uint8_t assn; /* affected sub system number */ |
Holger Hans Peter Freyther | 585f3d9 | 2010-07-31 04:38:17 +0800 | [diff] [blame] | 154 | uint16_t apoc; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 155 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 156 | uint8_t mul_ind : 2, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 157 | spare : 6; |
| 158 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 159 | uint8_t spare : 6, |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 160 | mul_ind : 2; |
| 161 | #endif |
| 162 | } __attribute__((packed)); |
| 163 | |
| 164 | #endif |