1 /* 2 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 3 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> 4 * 5 * Version: MPL 1.1 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 18 * 19 * The Initial Developer of the Original Code is 20 * Anthony Minessale II <anthm@freeswitch.org> 21 * Portions created by the Initial Developer are Copyright (C) 22 * the Initial Developer. All Rights Reserved. 23 * 24 * Contributor(s): 25 * 26 * Anthony Minessale II <anthm@freeswitch.org> 27 * 28 * mod_fsk -- FSK data transfer 29 * 30 */ 31 #ifndef __FSK_CALLER_ID_H 32 #define __FSK_CALLER_ID_H 33 SWITCH_BEGIN_EXTERN_C 34 #include "fsk.h" 35 #include "uart.h" 36 37 #define FSK_MOD_FACTOR 0x10000 38 39 typedef enum { 40 ENDIAN_BIG = 1, 41 ENDIAN_LITTLE = -1 42 } endian_t; 43 44 typedef enum { 45 CID_TYPE_SDMF = 0x04, 46 CID_TYPE_MDMF = 0x80 47 } cid_type_t; 48 49 typedef enum { 50 MDMF_DATETIME = 1, 51 MDMF_PHONE_NUM = 2, 52 MDMF_DDN = 3, 53 MDMF_NO_NUM = 4, 54 MDMF_PHONE_NAME = 7, 55 MDMF_NO_NAME = 8, 56 MDMF_ALT_ROUTE = 9, 57 MDMF_NAME_VALUE = 10, 58 MDMF_INVALID = 11 59 } mdmf_type_t; 60 61 struct bitstream { 62 uint8_t *data; 63 uint32_t datalen; 64 uint32_t byte_index; 65 uint8_t bit_index; 66 int8_t endian; 67 uint8_t top; 68 uint8_t bot; 69 uint8_t ss; 70 uint8_t ssv; 71 }; 72 73 struct fsk_data_state { 74 dsp_fsk_handle_t *fsk1200_handle; 75 uint8_t init; 76 uint8_t *buf; 77 size_t bufsize; 78 size_t blen; 79 size_t bpos; 80 size_t dlen; 81 size_t ppos; 82 int checksum; 83 }; 84 85 typedef struct bitstream bitstream_t; 86 typedef struct fsk_data_state fsk_data_state_t; 87 typedef switch_status_t (*fsk_write_sample_t)(int16_t *buf, size_t buflen, void *user_data); 88 89 struct fsk_modulator { 90 teletone_dds_state_t dds; 91 bitstream_t bs; 92 uint32_t carrier_bits_start; 93 uint32_t carrier_bits_stop; 94 uint32_t chan_sieze_bits; 95 uint32_t bit_factor; 96 uint32_t bit_accum; 97 uint32_t sample_counter; 98 int32_t samples_per_bit; 99 int32_t est_bytes; 100 fsk_modem_types_t modem_type; 101 fsk_data_state_t *fsk_data; 102 fsk_write_sample_t write_sample_callback; 103 void *user_data; 104 int16_t sample_buffer[64]; 105 }; 106 107 108 typedef int (*fsk_data_decoder_t)(fsk_data_state_t *state); 109 110 typedef void (*logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...); 111 typedef struct fsk_modulator fsk_modulator_t; 112 113 switch_status_t fsk_data_init(fsk_data_state_t *state, uint8_t *data, uint32_t datalen); 114 void bitstream_init(bitstream_t *bsp, uint8_t *data, uint32_t datalen, endian_t endian, uint8_t ss); 115 int8_t bitstream_get_bit(bitstream_t *bsp); 116 switch_status_t fsk_data_add_mdmf(fsk_data_state_t *state, mdmf_type_t type, const uint8_t *data, uint32_t datalen); 117 switch_status_t fsk_data_add_checksum(fsk_data_state_t *state); 118 switch_status_t fsk_data_parse(fsk_data_state_t *state, size_t *type, char **data, size_t *len); 119 switch_status_t fsk_demod_feed(fsk_data_state_t *state, int16_t *data, size_t samples); 120 switch_status_t fsk_demod_destroy(fsk_data_state_t *state); 121 int fsk_demod_init(fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); 122 size_t fsk_modulator_generate_bit(fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, size_t buflen); 123 int32_t fsk_modulator_generate_carrier_bits(fsk_modulator_t *fsk_trans, uint32_t bits); 124 void fsk_modulator_generate_chan_sieze(fsk_modulator_t *fsk_trans); 125 void fsk_modulator_send_data(fsk_modulator_t *fsk_trans); 126 switch_status_t fsk_modulator_init(fsk_modulator_t *fsk_trans, 127 fsk_modem_types_t modem_type, 128 uint32_t sample_rate, 129 fsk_data_state_t *fsk_data, 130 float db_level, 131 uint32_t carrier_bits_start, 132 uint32_t carrier_bits_stop, 133 uint32_t chan_sieze_bits, 134 fsk_write_sample_t write_sample_callback, 135 void *user_data); 136 137 138 #define fsk_modulator_send_all(_it) fsk_modulator_generate_chan_sieze(_it); \ 139 fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ 140 fsk_modulator_send_data(_it); \ 141 fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) 142 143 SWITCH_END_EXTERN_C 144 #endif 145