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" |
Neels Hofmeyr | 6a8b9c7 | 2018-03-22 15:51:22 +0100 | [diff] [blame] | 22 | #include <osmocom/core/logging.h> |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 23 | |
| 24 | int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode) |
| 25 | { |
| 26 | if ((dcs & 0xF0) == 0xF0) { |
| 27 | if (dcs & 0x04) { |
| 28 | /* bit 2 == 1: 8bit data */ |
| 29 | *data_coding = 0x02; |
| 30 | *mode = MODE_8BIT; |
| 31 | } else { |
| 32 | /* bit 2 == 0: default alphabet */ |
| 33 | *data_coding = 0x01; |
| 34 | *mode = MODE_7BIT; |
| 35 | } |
| 36 | } else if ((dcs & 0xE0) == 0) { |
| 37 | switch (dcs & 0xC) { |
| 38 | case 0: |
| 39 | *data_coding = 0x01; |
| 40 | *mode = MODE_7BIT; |
| 41 | break; |
| 42 | case 4: |
| 43 | *data_coding = 0x02; |
| 44 | *mode = MODE_8BIT; |
| 45 | break; |
| 46 | case 8: |
| 47 | *data_coding = 0x08; /* UCS-2 */ |
| 48 | *mode = MODE_8BIT; |
| 49 | break; |
| 50 | default: |
| 51 | goto unknown_mo; |
| 52 | } |
| 53 | } else { |
| 54 | unknown_mo: |
| 55 | LOGP(DLSMS, LOGL_ERROR, "SMPP MO Unknown Data Coding 0x%02x\n", dcs); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | return 0; |
| 60 | |
| 61 | } |