Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 1 | /* Create GSM 08.08 messages */ |
| 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 | #include <bssap_sccp.h> |
Holger Hans Peter Freyther | cbf7d18 | 2010-07-31 05:25:35 +0800 | [diff] [blame] | 24 | #include <cellmgr_debug.h> |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 25 | |
Holger Hans Peter Freyther | cbf7d18 | 2010-07-31 05:25:35 +0800 | [diff] [blame] | 26 | #include <osmocore/msgb.h> |
Holger Hans Peter Freyther | e66c7c1 | 2010-08-04 18:51:16 +0800 | [diff] [blame] | 27 | #include <osmocore/protocol/gsm_08_08.h> |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 28 | |
| 29 | #include <string.h> |
| 30 | |
| 31 | |
| 32 | struct msgb *create_clear_command(struct sccp_source_reference *dest_ref) |
| 33 | { |
| 34 | struct sccp_data_form1 *form1; |
| 35 | struct msgb *msg; |
| 36 | |
| 37 | msg = msgb_alloc_headroom(4096, 128, "clear command"); |
| 38 | if (!msg) { |
| 39 | LOGP(DINP, LOGL_ERROR, "Failed to allocate clear command.\n"); |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | msg->l2h = msgb_put(msg, sizeof(*form1)); |
| 44 | form1 = (struct sccp_data_form1 *) msg->l2h; |
| 45 | form1->type = SCCP_MSG_TYPE_DT1; |
| 46 | form1->destination_local_reference = *dest_ref; |
| 47 | form1->segmenting = 0; |
| 48 | form1->variable_start = 1; |
| 49 | |
| 50 | /* create a Clear Command Call Control msg */ |
| 51 | msg->l3h = msgb_put(msg, 7); |
| 52 | msg->l3h[0] = msgb_l3len(msg) - 1; |
| 53 | msg->l3h[1] = BSSAP_MSG_BSS_MANAGEMENT; |
| 54 | msg->l3h[2] = msg->l3h[0] - 2; |
| 55 | msg->l3h[3] = BSS_MAP_MSG_CLEAR_CMD; |
| 56 | msg->l3h[4] = 4; |
| 57 | msg->l3h[5] = 1; |
| 58 | msg->l3h[6] = 0x09; |
| 59 | |
| 60 | return msg; |
| 61 | } |
| 62 | |
| 63 | struct msgb *create_sccp_rlsd(struct sccp_source_reference *src_ref, |
| 64 | struct sccp_source_reference *dst_ref) |
| 65 | { |
| 66 | struct sccp_connection_released *rel; |
| 67 | struct msgb *msg; |
| 68 | |
| 69 | msg = msgb_alloc_headroom(4096, 128, "rlsd"); |
| 70 | if (!msg) { |
| 71 | LOGP(DINP, LOGL_ERROR, "Failed to allocate clear command.\n"); |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | msg->l2h = msgb_put(msg, sizeof(*rel)); |
| 76 | rel = (struct sccp_connection_released *) msg->l2h; |
| 77 | rel->type = SCCP_MSG_TYPE_RLSD; |
| 78 | rel->release_cause = SCCP_RELEASE_CAUSE_END_USER_ORIGINATED; |
| 79 | rel->destination_local_reference = *dst_ref; |
| 80 | rel->source_local_reference = *src_ref; |
| 81 | |
| 82 | return msg; |
| 83 | } |
| 84 | |
| 85 | struct msgb *create_sccp_rlc(struct sccp_source_reference *src_ref, |
| 86 | struct sccp_source_reference *dst_ref) |
| 87 | { |
| 88 | struct sccp_connection_release_complete *rlc; |
| 89 | struct msgb *msg; |
| 90 | |
| 91 | msg = msgb_alloc_headroom(4096, 128, "rlc"); |
| 92 | if (!msg) { |
| 93 | LOGP(DINP, LOGL_ERROR, "Failed to allocate rlc.\n"); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | msg->l2h = msgb_put(msg, sizeof(*rlc)); |
| 98 | rlc = (struct sccp_connection_release_complete *) msg->l2h; |
| 99 | rlc->type = SCCP_MSG_TYPE_RLC; |
| 100 | rlc->destination_local_reference = *dst_ref; |
| 101 | rlc->source_local_reference = *src_ref; |
| 102 | |
| 103 | return msg; |
| 104 | } |
| 105 | |
| 106 | struct msgb *create_sccp_refuse(struct sccp_source_reference *dest_ref) |
| 107 | { |
| 108 | struct sccp_connection_refused *ref; |
| 109 | struct msgb *msg; |
| 110 | |
| 111 | msg = msgb_alloc_headroom(4096, 128, "rlsd"); |
| 112 | if (!msg) { |
| 113 | LOGP(DINP, LOGL_ERROR, "Failed to allocate connection refuse.\n"); |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | msg->l2h = msgb_put(msg, sizeof(*ref)); |
| 118 | ref = (struct sccp_connection_refused *) msg->l2h; |
| 119 | ref->type = SCCP_MSG_TYPE_CREF; |
| 120 | ref->destination_local_reference = *dest_ref; |
| 121 | ref->cause = SCCP_REFUSAL_END_USER_ORIGINATED; |
| 122 | ref->optional_start = 1; |
| 123 | |
| 124 | msg->l3h = msgb_put(msg, 1); |
| 125 | msg->l3h[0] = SCCP_PNC_END_OF_OPTIONAL; |
| 126 | |
| 127 | return msg; |
| 128 | } |
| 129 | |
| 130 | struct msgb *create_reset() |
| 131 | { |
Holger Hans Peter Freyther | 5aa1701 | 2010-07-31 04:37:26 +0800 | [diff] [blame] | 132 | static const uint8_t reset[] = { |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 133 | 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe, |
| 134 | 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04, |
| 135 | 0x01, 0x20 |
| 136 | }; |
| 137 | |
| 138 | struct msgb *msg; |
| 139 | |
| 140 | msg = msgb_alloc_headroom(4096, 128, "reset"); |
| 141 | if (!msg) { |
| 142 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate reset msg.\n"); |
| 143 | return NULL; |
| 144 | } |
| 145 | |
| 146 | msg->l2h = msgb_put(msg, sizeof(reset)); |
| 147 | memcpy(msg->l2h, reset, msgb_l2len(msg)); |
| 148 | return msg; |
| 149 | } |