| 1 | #include "fep.h" |
|---|
| 2 | #include "hexdump.c" |
|---|
| 3 | |
|---|
| 4 | /* The following get_*_text functions are helper functions used to |
|---|
| 5 | get enum type names as strings */ |
|---|
| 6 | const char* get_polltype_text(enum polltype ptype) |
|---|
| 7 | { |
|---|
| 8 | switch(ptype) |
|---|
| 9 | { |
|---|
| 10 | case POLL: |
|---|
| 11 | return "POLL"; |
|---|
| 12 | case COMMAND: |
|---|
| 13 | return "COMMAND"; |
|---|
| 14 | case TIMESYNC: |
|---|
| 15 | return "TIMESYNC"; |
|---|
| 16 | default: |
|---|
| 17 | return "UNKNOWN"; |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | const char* get_status_text(enum errorstatus estat) |
|---|
| 22 | { |
|---|
| 23 | switch(estat) |
|---|
| 24 | { case FEP_OK: |
|---|
| 25 | return "FEP_OK"; |
|---|
| 26 | case FEP_OUTOFRANGE: |
|---|
| 27 | return "FEP_OUTOFRANGE"; |
|---|
| 28 | case FEP_BADHANDLE: |
|---|
| 29 | return "FEP_BADHANDLE"; |
|---|
| 30 | case FEP_NOREPLY: |
|---|
| 31 | return "FEP_NOREPLY"; |
|---|
| 32 | case FEP_SCHBUSY: |
|---|
| 33 | return "FEP_SCHBUSY"; |
|---|
| 34 | case FEP_LINEBUSY: |
|---|
| 35 | return "FEP_LINEBUSY"; |
|---|
| 36 | case FEP_REPORTBUSY: |
|---|
| 37 | return "FEP_REPORTBUSY"; |
|---|
| 38 | case FEP_NOREPORT: |
|---|
| 39 | return "FEP_NOREPORT"; |
|---|
| 40 | case FEP_NOMEMORY: |
|---|
| 41 | return "FEP_NOMEMORY"; |
|---|
| 42 | case FEP_BADTIME: |
|---|
| 43 | return "FEP_BADTIME"; |
|---|
| 44 | case FEP_BADTIMESYNCH: |
|---|
| 45 | return "FEP_BADTIMESYNCH"; |
|---|
| 46 | case FEP_BADKIND: |
|---|
| 47 | return "FEP_BADKIND"; |
|---|
| 48 | case FEP_BADCONNECT: |
|---|
| 49 | return "FEP_BADCONNECT"; |
|---|
| 50 | case FEP_NOAUTHORITY: |
|---|
| 51 | return "FEP_NOAUTHORITY"; |
|---|
| 52 | default: |
|---|
| 53 | return "UNKNOWN"; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | const char* get_answererror_text(enum answererror err) |
|---|
| 58 | { |
|---|
| 59 | switch(err) |
|---|
| 60 | { |
|---|
| 61 | case ERR_BSCF_ERR: |
|---|
| 62 | return "ERR_BSCF_ERR"; |
|---|
| 63 | case ERR_NONE: |
|---|
| 64 | return "ERR_NONE"; |
|---|
| 65 | case ERR_MSG_LEN: |
|---|
| 66 | return "ERR_MSG_LEN"; |
|---|
| 67 | case ERR_MSG_HDR: |
|---|
| 68 | return "ERR_MSG_HDR"; |
|---|
| 69 | case ERR_MSG_CHKSUM: |
|---|
| 70 | return "ERR_MSG_CHKSUM"; |
|---|
| 71 | case ERR_MSG_TRAILER: |
|---|
| 72 | return "ERR_MSG_TRAILER"; |
|---|
| 73 | default: |
|---|
| 74 | return "UNKNOWN"; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | const char * get_pollingfsm_text(enum Polling_FSM_States state) |
|---|
| 79 | { |
|---|
| 80 | switch(state) |
|---|
| 81 | { |
|---|
| 82 | case INITSTATE: |
|---|
| 83 | return "INITSTATE"; |
|---|
| 84 | case WRALARMSTATE: |
|---|
| 85 | return "WRALARMSTATE"; |
|---|
| 86 | case CLRSTATE: |
|---|
| 87 | return "CLRSTATE"; |
|---|
| 88 | case RTSONSTATE: |
|---|
| 89 | return "RTSONSTATE"; |
|---|
| 90 | case CTSSTATE: |
|---|
| 91 | return "CTSSTATE"; |
|---|
| 92 | case WRITESTATE: |
|---|
| 93 | return "WRITESTATE"; |
|---|
| 94 | case RTSOFFSTATE: |
|---|
| 95 | return "RTSOFFSTATE"; |
|---|
| 96 | case RDALARMSTATE: |
|---|
| 97 | return "RDALARMSTATE"; |
|---|
| 98 | case RDSTATE: |
|---|
| 99 | return "RDSTATE"; |
|---|
| 100 | case DONESTATE: |
|---|
| 101 | return "DONESTATE"; |
|---|
| 102 | default: |
|---|
| 103 | return "UNKNOWN"; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | const char *get_replystatus_text(enum replystatus status) |
|---|
| 108 | { |
|---|
| 109 | switch(status) |
|---|
| 110 | { |
|---|
| 111 | case FAILURE: |
|---|
| 112 | return "FAILURE"; |
|---|
| 113 | case DONE: |
|---|
| 114 | return "DONE"; |
|---|
| 115 | case UNUSED: |
|---|
| 116 | return "UNUSED"; |
|---|
| 117 | default: |
|---|
| 118 | return "UNKNOWN"; |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | const char *get_replykind_text(enum replykind kind) |
|---|
| 123 | { |
|---|
| 124 | switch(kind) |
|---|
| 125 | { |
|---|
| 126 | case POLLREPLY: |
|---|
| 127 | return "POLLREPLY"; |
|---|
| 128 | case SCHEDNEW: |
|---|
| 129 | return "SCHEDNEW"; |
|---|
| 130 | case SCHEDDONE: |
|---|
| 131 | return "SCHEDDONE"; |
|---|
| 132 | default: |
|---|
| 133 | return "UNKNOWN"; |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /* The following functions are used to print fep_reply, reply_ret structs and associated structs */ |
|---|
| 138 | void print_fep_pollerror(fep_pollerror pollerror) |
|---|
| 139 | { |
|---|
| 140 | printf("\t\t\t\t\t\tpoll error:\n"); |
|---|
| 141 | printf("\t\t\t\t\t\tanswererror msgerror:\t%s\n", get_answererror_text(pollerror.msgerror)); |
|---|
| 142 | printf("\t\t\t\t\t\tPolling_FSM_States state:\t%s\n", get_pollingfsm_text(pollerror.state)); |
|---|
| 143 | printf("\t\t\t\t\t\t\tint perrno:\t%d\n", pollerror.perrno); |
|---|
| 144 | printf("\t\t\t\t\t\t\tint termination:\t%d\n", pollerror.termination); |
|---|
| 145 | printf("\t\t\t\t\t\t\tint count:\t%d\n", pollerror.count); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void print_fep_answer_info(fep_answer_info info) |
|---|
| 149 | { |
|---|
| 150 | printf("\t\t\t\t\tfep_answer_info:\n"); |
|---|
| 151 | printf("\t\t\t\t\t\tlong poll_time:\t%ld\n", info.poll_time); |
|---|
| 152 | printf("\t\t\t\t\t\treplystatus status:\t%s\n", get_replystatus_text(info.status)); |
|---|
| 153 | printf("\t\t\t\t\t\tint poll_user_info1:\t%d\n", info.poll_user_info1); |
|---|
| 154 | printf("\t\t\t\t\t\tint poll_user_info2:\t%d\n", info.poll_user_info2); |
|---|
| 155 | printf("\t\t\t\t\t\tint retries:\t%d\n", info.retries); |
|---|
| 156 | printf("\t\t\t\t\t\tint poll_error_count:\t%d\n", info.poll_error_count); |
|---|
| 157 | for(int i = 0; i < info.poll_error_count; i++) |
|---|
| 158 | { |
|---|
| 159 | print_fep_pollerror(*info.pollerror); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | void print_fep_answer_short_msg(fep_answer_short_msg msg) |
|---|
| 164 | { |
|---|
| 165 | printf("\t\t\t\t\tfep_answer_short:\n"); |
|---|
| 166 | printf("\t\t\t\t\t\tint message_len:\t%d\n", msg.message_len); |
|---|
| 167 | printf("\t\t\t\t\t\tmessage:\t"); |
|---|
| 168 | for(int i = 0; i < msg.message_len; i++) |
|---|
| 169 | { |
|---|
| 170 | printf("%04x ", msg.message[i]); |
|---|
| 171 | } |
|---|
| 172 | printf("\n"); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | void print_fep_shortanswer(fep_shortanswer answer) |
|---|
| 176 | { |
|---|
| 177 | printf("\t\t\t\tfep_shortanswer:\n"); |
|---|
| 178 | print_fep_answer_info(answer.info); |
|---|
| 179 | print_fep_answer_short_msg(answer.msg); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | void print_fep_shortanswer_list(fep_shortanswer_list answer_list) |
|---|
| 183 | { |
|---|
| 184 | printf("\t\t\tfep_shortanswer_list:\n"); |
|---|
| 185 | printf("\t\t\t\tcount:\t%d\n", answer_list.count); |
|---|
| 186 | for(int i = 0; i < answer_list.count; i++) |
|---|
| 187 | { |
|---|
| 188 | print_fep_shortanswer(answer_list.answers[i]); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | void print_fep_answer_list(fep_answer_list answers) |
|---|
| 193 | { |
|---|
| 194 | printf("\t\tfep_answer_list:\n"); |
|---|
| 195 | printf("\t\t\tint size:\t%d\n", answers.size); |
|---|
| 196 | print_fep_shortanswer_list(answers.fep_answer_list_u.shortp); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | void print_fep_reply(fep_reply reply) |
|---|
| 200 | { |
|---|
| 201 | printf("\tfep_reply: \n"); |
|---|
| 202 | printf("\t\tint reply:\t%d\n", reply.reply); |
|---|
| 203 | printf("\t\tint schedule:\t%d\n", reply.schedule); |
|---|
| 204 | printf("\t\tint lineinfo:\t%d\n", reply.lineinfo); |
|---|
| 205 | printf("\t\tpolltype kind:\t%s\n", get_polltype_text(reply.kind)); |
|---|
| 206 | printf("\t\treplykind flag:\t%s\n", get_replykind_text(reply.flag)); |
|---|
| 207 | printf("\t\tint schedule_sequence:\t%d\n", reply.schedule_sequence); |
|---|
| 208 | printf("\t\tint global_sequence:\t%d\n", reply.global_sequence); |
|---|
| 209 | printf("\t\tlong schedule_time:\t%ld\n", reply.schedule_time); |
|---|
| 210 | printf("\t\tint user_info1:\t%d\n", reply.user_info1); |
|---|
| 211 | printf("\t\tint user_info2:\t%d\n", reply.user_info2); |
|---|
| 212 | print_fep_answer_list(reply.answers); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | /* Dumps the ATMS's response to RPC Call (struct reply_ret) */ |
|---|
| 216 | void print_reply_ret(reply_ret response) { |
|---|
| 217 | printf("reply_ret:\n"); |
|---|
| 218 | // Print response status |
|---|
| 219 | printf("\tfep_status: %s\n", get_status_text(response.status)); |
|---|
| 220 | print_fep_reply(response.reply_ret_u.info); |
|---|
| 221 | } |
|---|