Rev 3443 | Rev 3452 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3443 | Rev 3444 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | #include <stdlib.h> |
36 | #include <stdlib.h> |
37 | #include <libadt/hash_table.h> |
37 | #include <libadt/hash_table.h> |
38 | 38 | ||
39 | #include "ipc_desc.h" |
39 | #include "ipc_desc.h" |
40 | #include "proto.h" |
40 | #include "proto.h" |
- | 41 | #include "trace.h" |
|
41 | #include "ipcp.h" |
42 | #include "ipcp.h" |
42 | 43 | ||
43 | #define IPCP_CALLID_SYNC 0 |
44 | #define IPCP_CALLID_SYNC 0 |
44 | 45 | ||
45 | typedef struct { |
46 | typedef struct { |
Line 175... | Line 176... | ||
175 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
176 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
176 | { |
177 | { |
177 | pending_call_t *pcall; |
178 | pending_call_t *pcall; |
178 | proto_t *proto; |
179 | proto_t *proto; |
179 | unsigned long key[1]; |
180 | unsigned long key[1]; |
- | 181 | oper_t *oper; |
|
180 | 182 | ||
181 | if (have_conn[phone]) proto = connections[phone].proto; |
183 | if (have_conn[phone]) proto = connections[phone].proto; |
182 | else proto = NULL; |
184 | else proto = NULL; |
183 | 185 | ||
184 | // printf("ipcp_call_out()\n"); |
186 | if ((display_mask & DM_IPC) != 0) { |
185 | printf("call id: 0x%x, phone: %d, proto: %s, method: ", hash, phone, |
187 | printf("Call ID: 0x%x, phone: %d, proto: %s, method: ", hash, |
186 | (proto ? proto->name : "n/a")); |
188 | phone, (proto ? proto->name : "n/a")); |
187 | ipc_m_print(proto, IPC_GET_METHOD(*call)); |
189 | ipc_m_print(proto, IPC_GET_METHOD(*call)); |
188 | printf(" args: (%u, %u, %u, %u, %u)\n", |
190 | printf(" args: (%u, %u, %u, %u, %u)\n", |
189 | IPC_GET_ARG1(*call), |
191 | IPC_GET_ARG1(*call), |
190 | IPC_GET_ARG2(*call), |
192 | IPC_GET_ARG2(*call), |
191 | IPC_GET_ARG3(*call), |
193 | IPC_GET_ARG3(*call), |
192 | IPC_GET_ARG4(*call), |
194 | IPC_GET_ARG4(*call), |
193 | IPC_GET_ARG5(*call) |
195 | IPC_GET_ARG5(*call) |
194 | ); |
196 | ); |
- | 197 | } |
|
- | 198 | ||
- | 199 | ||
- | 200 | if ((display_mask & DM_USER) != 0) { |
|
- | 201 | ||
- | 202 | if (proto != NULL) { |
|
- | 203 | oper = proto_get_oper(proto, IPC_GET_METHOD(*call)); |
|
- | 204 | } else { |
|
- | 205 | oper = NULL; |
|
- | 206 | } |
|
- | 207 | ||
- | 208 | if (oper != NULL) { |
|
- | 209 | ||
- | 210 | printf("%s(%d).%s", (proto ? proto->name : "n/a"), |
|
- | 211 | phone, (oper ? oper->name : "unknown")); |
|
- | 212 | ||
- | 213 | printf("(%u, %u, %u, %u, %u)\n", |
|
- | 214 | IPC_GET_ARG1(*call), |
|
- | 215 | IPC_GET_ARG2(*call), |
|
- | 216 | IPC_GET_ARG3(*call), |
|
- | 217 | IPC_GET_ARG4(*call), |
|
- | 218 | IPC_GET_ARG5(*call) |
|
- | 219 | ); |
|
- | 220 | } |
|
- | 221 | } |
|
195 | 222 | ||
196 | /* Store call in hash table for response matching */ |
223 | /* Store call in hash table for response matching */ |
197 | 224 | ||
198 | pcall = malloc(sizeof(pending_call_t)); |
225 | pcall = malloc(sizeof(pending_call_t)); |
199 | pcall->phone_hash = phone; |
226 | pcall->phone_hash = phone; |
Line 203... | Line 230... | ||
203 | key[0] = hash; |
230 | key[0] = hash; |
204 | 231 | ||
205 | hash_table_insert(&pending_calls, key, &pcall->link); |
232 | hash_table_insert(&pending_calls, key, &pcall->link); |
206 | } |
233 | } |
207 | 234 | ||
208 | static void parse_answer(pending_call_t *pcall, ipc_call_t *answer) |
235 | static void parse_answer(ipc_callid_t hash, pending_call_t *pcall, |
- | 236 | ipc_call_t *answer) |
|
209 | { |
237 | { |
210 | int phone; |
238 | int phone; |
211 | ipcarg_t method; |
239 | ipcarg_t method; |
212 | ipcarg_t service; |
240 | ipcarg_t service; |
213 | int retval; |
241 | int retval; |
Line 217... | Line 245... | ||
217 | // printf("parse_answer\n"); |
245 | // printf("parse_answer\n"); |
218 | 246 | ||
219 | phone = pcall->phone_hash; |
247 | phone = pcall->phone_hash; |
220 | method = IPC_GET_METHOD(pcall->question); |
248 | method = IPC_GET_METHOD(pcall->question); |
221 | retval = IPC_GET_RETVAL(*answer); |
249 | retval = IPC_GET_RETVAL(*answer); |
- | 250 | ||
- | 251 | if ((display_mask & DM_IPC) != 0) { |
|
222 | printf("phone=%d, method=%d, retval=%d\n", |
252 | printf("Response to 0x%x: retval=%d, args = (%u, %u, %u, %u, %u)\n", |
- | 253 | hash, retval, IPC_GET_ARG1(*answer), |
|
- | 254 | IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), |
|
- | 255 | IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer)); |
|
- | 256 | } |
|
- | 257 | ||
- | 258 | if ((display_mask & DM_USER) != 0) { |
|
223 | phone, method, retval); |
259 | printf("-> %d\n", retval); |
- | 260 | } |
|
224 | 261 | ||
225 | if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
262 | if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
226 | /* Connected to a service (through NS) */ |
263 | /* Connected to a service (through NS) */ |
227 | service = IPC_GET_ARG1(pcall->question); |
264 | service = IPC_GET_ARG1(pcall->question); |
228 | proto = proto_get_by_srv(service); |
265 | proto = proto_get_by_srv(service); |
229 | if (proto == NULL) proto = proto_unknown; |
266 | if (proto == NULL) proto = proto_unknown; |
230 | 267 | ||
231 | cphone = IPC_GET_ARG5(*answer); |
268 | cphone = IPC_GET_ARG5(*answer); |
- | 269 | if ((display_mask & DM_SYSTEM) != 0) { |
|
232 | printf("registering connection (phone %d, protocol: %s)\n", cphone, |
270 | printf("Registering connection (phone %d, protocol: %s)\n", cphone, |
233 | proto->name); |
271 | proto->name); |
- | 272 | } |
|
234 | ipcp_connection_set(cphone, 0, proto); |
273 | ipcp_connection_set(cphone, 0, proto); |
235 | } |
274 | } |
236 | } |
275 | } |
237 | 276 | ||
238 | void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash) |
277 | void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash) |
Line 252... | Line 291... | ||
252 | IPC_GET_ARG5(*call) |
291 | IPC_GET_ARG5(*call) |
253 | );*/ |
292 | );*/ |
254 | 293 | ||
255 | if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) { |
294 | if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) { |
256 | /* Not a response */ |
295 | /* Not a response */ |
- | 296 | if ((display_mask & DM_IPC) != 0) { |
|
257 | printf("Not a response (hash %d)\n", hash); |
297 | printf("Not a response (hash %d)\n", hash); |
- | 298 | } |
|
258 | return; |
299 | return; |
259 | } |
300 | } |
260 | 301 | ||
261 | hash = hash & ~IPC_CALLID_ANSWERED; |
302 | hash = hash & ~IPC_CALLID_ANSWERED; |
262 | key[0] = hash; |
303 | key[0] = hash; |
263 | 304 | ||
264 | item = hash_table_find(&pending_calls, key); |
305 | item = hash_table_find(&pending_calls, key); |
265 | if (item == NULL) return; // No matching question found |
306 | if (item == NULL) return; // No matching question found |
266 | 307 | ||
- | 308 | /* |
|
267 | pcall = hash_table_get_instance(item, pending_call_t, link); |
309 | * Response matched to question. |
- | 310 | */ |
|
268 | 311 | ||
269 | printf("response matched to question\n"); |
312 | pcall = hash_table_get_instance(item, pending_call_t, link); |
270 | hash_table_remove(&pending_calls, key, 1); |
313 | hash_table_remove(&pending_calls, key, 1); |
271 | 314 | ||
272 | parse_answer(pcall, call); |
315 | parse_answer(hash, pcall, call); |
273 | free(pcall); |
316 | free(pcall); |
274 | } |
317 | } |
275 | 318 | ||
276 | void ipcp_call_sync(int phone, ipc_call_t *call, ipc_call_t *answer) |
319 | void ipcp_call_sync(int phone, ipc_call_t *call, ipc_call_t *answer) |
277 | { |
320 | { |
Line 279... | Line 322... | ||
279 | ipcp_call_in(answer, IPCP_CALLID_SYNC); |
322 | ipcp_call_in(answer, IPCP_CALLID_SYNC); |
280 | } |
323 | } |
281 | 324 | ||
282 | void ipcp_hangup(int phone, int rc) |
325 | void ipcp_hangup(int phone, int rc) |
283 | { |
326 | { |
- | 327 | if ((display_mask & DM_SYSTEM) != 0) { |
|
284 | printf("hangup phone %d -> %d\n", phone, rc); |
328 | printf("Hang phone %d up -> %d\n", phone, rc); |
285 | ipcp_connection_clear(phone); |
329 | ipcp_connection_clear(phone); |
286 | } |
330 | } |
- | 331 | } |
|
287 | 332 | ||
288 | /** @} |
333 | /** @} |
289 | */ |
334 | */ |