Harald Welte | 1fbcd1c | 2011-01-15 20:51:53 +0100 | [diff] [blame] | 1 | % ITU-T Q.704 (MTP Level 3) coding / decoding |
| 2 | |
| 3 | % (C) 2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | % |
| 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 Affero General Public License as |
| 9 | % published by the Free Software Foundation; either version 3 of the |
| 10 | % License, or (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 Affero General Public License |
| 18 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | -module(mtp3_codec). |
| 21 | -author('Harald Welte <laforge@gnumonks.org>'). |
| 22 | -include("mtp3.hrl"). |
| 23 | |
| 24 | -export([parse_mtp3_msg/1, encode_mtp3_msg/1]). |
| 25 | |
| 26 | % Parse standard routing label according to Section 2.2 of ITU-T Q.704 |
| 27 | parse_mtp3_routing_label(_, LabelBin) when is_binary(LabelBin) -> |
| 28 | <<Sls:4/big, Opc:14/big, Dpc:14/big, Remain/binary>> = LabelBin, |
| 29 | {ok, #mtp3_routing_label{sig_link_sel = Sls, origin_pc = Opc, dest_pc = Dpc}, Remain}. |
| 30 | |
| 31 | parse_mtp3_msg(DataBin) when is_binary(DataBin) -> |
| 32 | <<NetInd:2, 0:2, ServiceInd:4, Remain/binary>> = DataBin, |
| 33 | {ok, RoutLbl, Payload} = parse_mtp3_routing_label(ServiceInd, Remain), |
| 34 | #mtp3_msg{network_ind = NetInd, service_ind = ServiceInd, routing_label = RoutLbl, |
| 35 | payload = Payload}. |
| 36 | |
| 37 | |
| 38 | encode_mtp3_routing_label(#mtp3_routing_label{sig_link_sel = Sls, origin_pc = Opc, |
| 39 | dest_pc = Dpc}) -> |
| 40 | <<Sls:4/big, Opc:14/big, Dpc:14/big>>. |
| 41 | |
| 42 | encode_mtp3_msg(#mtp3_msg{network_ind = NetInd, service_ind = ServiceInd, |
| 43 | routing_label = RoutLbl, payload = Payload}) -> |
| 44 | RoutLblBin = encode_mtp3_routing_label(RoutLbl), |
| 45 | <<NetInd:2, 0:2, ServiceInd:4, RoutLblBin/binary, Payload/binary>>. |
| 46 | |