Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 1 | |
| 2 | /* (C) 2012-2013 by Harald Welte <laforge@gnumonks.org> |
| 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include "smpp_smsc.h" |
| 22 | #include <openbsc/debug.h> |
| 23 | |
| 24 | |
| 25 | int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode) |
| 26 | { |
| 27 | if ((dcs & 0xF0) == 0xF0) { |
| 28 | if (dcs & 0x04) { |
| 29 | /* bit 2 == 1: 8bit data */ |
| 30 | *data_coding = 0x02; |
| 31 | *mode = MODE_8BIT; |
| 32 | } else { |
| 33 | /* bit 2 == 0: default alphabet */ |
| 34 | *data_coding = 0x01; |
| 35 | *mode = MODE_7BIT; |
| 36 | } |
| 37 | } else if ((dcs & 0xE0) == 0) { |
| 38 | switch (dcs & 0xC) { |
| 39 | case 0: |
| 40 | *data_coding = 0x01; |
| 41 | *mode = MODE_7BIT; |
| 42 | break; |
| 43 | case 4: |
| 44 | *data_coding = 0x02; |
| 45 | *mode = MODE_8BIT; |
| 46 | break; |
| 47 | case 8: |
| 48 | *data_coding = 0x08; /* UCS-2 */ |
| 49 | *mode = MODE_8BIT; |
| 50 | break; |
| 51 | default: |
| 52 | goto unknown_mo; |
| 53 | } |
| 54 | } else { |
| 55 | unknown_mo: |
| 56 | LOGP(DLSMS, LOGL_ERROR, "SMPP MO Unknown Data Coding 0x%02x\n", dcs); |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | |
| 62 | } |