Holger Freyther | 76c9569 | 2009-02-17 20:31:30 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de> |
| 3 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.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 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 <openbsc/gsm_utils.h> |
| 24 | #include <malloc.h> |
| 25 | |
| 26 | char *gsm_7bit_decode(u_int8_t *user_data, u_int8_t length) |
| 27 | { |
| 28 | u_int8_t d_off = 0, b_off = 0; |
| 29 | u_int8_t i; |
| 30 | char *text = malloc(length+1); |
| 31 | |
| 32 | for (i=0;i<length;i++) { |
| 33 | text[i] = ((user_data[d_off] + (user_data[d_off+1]<<8)) & (0x7f<<b_off))>>b_off; |
| 34 | b_off += 7; |
| 35 | if (b_off >= 8) { |
| 36 | d_off += 1; |
| 37 | b_off -= 8; |
| 38 | } |
| 39 | } |
| 40 | text[i] = 0; |
| 41 | return text; |
| 42 | } |