Rev 2874 | Rev 2878 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2874 | Rev 2877 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | #include <libadt/hash_table.h> |
9 | #include <libadt/hash_table.h> |
10 | 10 | ||
11 | #include "ipc_desc.h" |
11 | #include "ipc_desc.h" |
12 | #include "ipcp.h" |
12 | #include "ipcp.h" |
13 | 13 | ||
- | 14 | #define IPCP_CALLID_SYNC 0 |
|
- | 15 | ||
14 | typedef struct { |
16 | typedef struct { |
15 | int phone_hash; |
17 | int phone_hash; |
16 | ipc_call_t question; |
18 | ipc_call_t question; |
17 | 19 | ||
18 | int call_hash; |
20 | int call_hash; |
Line 32... | Line 34... | ||
32 | #define PCALL_TABLE_CHAINS 32 |
34 | #define PCALL_TABLE_CHAINS 32 |
33 | hash_table_t pending_calls; |
35 | hash_table_t pending_calls; |
34 | 36 | ||
35 | hash_index_t pending_call_hash(unsigned long key[]) |
37 | hash_index_t pending_call_hash(unsigned long key[]) |
36 | { |
38 | { |
37 | printf("pending_call_hash\n"); |
39 | // printf("pending_call_hash\n"); |
38 | return key[0] % PCALL_TABLE_CHAINS; |
40 | return key[0] % PCALL_TABLE_CHAINS; |
39 | } |
41 | } |
40 | 42 | ||
41 | int pending_call_compare(unsigned long key[], hash_count_t keys, link_t *item) |
43 | int pending_call_compare(unsigned long key[], hash_count_t keys, |
- | 44 | link_t *item) |
|
42 | { |
45 | { |
43 | pending_call_t *hs; |
46 | pending_call_t *hs; |
44 | 47 | ||
45 | printf("pending_call_remove_compare\n"); |
48 | // printf("pending_call_compare\n"); |
46 | hs = hash_table_get_instance(item, pending_call_t, link); |
49 | hs = hash_table_get_instance(item, pending_call_t, link); |
47 | 50 | ||
48 | return key[0] == hs->call_hash; |
51 | return key[0] == hs->call_hash; |
49 | } |
52 | } |
50 | 53 | ||
51 | void pending_call_remove_callback(link_t *item) |
54 | void pending_call_remove_callback(link_t *item) |
52 | { |
55 | { |
53 | printf("pending_call_remove_callback\n"); |
56 | // printf("pending_call_remove_callback\n"); |
54 | } |
57 | } |
55 | 58 | ||
56 | hash_table_operations_t pending_call_ops = { |
59 | hash_table_operations_t pending_call_ops = { |
57 | .hash = pending_call_hash, |
60 | .hash = pending_call_hash, |
58 | .compare = pending_call_compare, |
61 | .compare = pending_call_compare, |
Line 103... | Line 106... | ||
103 | } |
106 | } |
104 | 107 | ||
105 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
108 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
106 | { |
109 | { |
107 | pending_call_t *pcall; |
110 | pending_call_t *pcall; |
- | 111 | char *proto_name; |
|
- | 112 | ||
- | 113 | if (have_conn[phone]) proto_name = connections[phone].proto->name; |
|
- | 114 | else proto_name = "n/a"; |
|
108 | 115 | ||
109 | // printf("ipcp_call_out()\n"); |
116 | // printf("ipcp_call_out()\n"); |
110 | printf("call id: 0x%x, phone: %d, method: ", hash, phone); |
117 | printf("call id: 0x%x, phone: %d, proto: %s, method: ", hash, phone, |
- | 118 | proto_name); |
|
111 | ipc_m_print(IPC_GET_METHOD(*call)); |
119 | ipc_m_print(IPC_GET_METHOD(*call)); |
112 | printf(" args: (%u, %u, %u, %u, %u)\n", |
120 | printf(" args: (%u, %u, %u, %u, %u)\n", |
113 | IPC_GET_ARG1(*call), |
121 | IPC_GET_ARG1(*call), |
114 | IPC_GET_ARG2(*call), |
122 | IPC_GET_ARG2(*call), |
115 | IPC_GET_ARG3(*call), |
123 | IPC_GET_ARG3(*call), |
Line 125... | Line 133... | ||
125 | pcall->call_hash = hash; |
133 | pcall->call_hash = hash; |
126 | 134 | ||
127 | hash_table_insert(&pending_calls, &pcall->call_hash, &pcall->link); |
135 | hash_table_insert(&pending_calls, &pcall->call_hash, &pcall->link); |
128 | } |
136 | } |
129 | 137 | ||
- | 138 | static void parse_answer(pending_call_t *pcall, ipc_call_t *answer) |
|
- | 139 | { |
|
- | 140 | int phone; |
|
- | 141 | ipcarg_t method; |
|
- | 142 | int retval; |
|
- | 143 | static proto_t proto = { .name = "unknown" }; |
|
- | 144 | int cphone; |
|
- | 145 | ||
- | 146 | // printf("parse_answer\n"); |
|
- | 147 | ||
- | 148 | phone = pcall->phone_hash; |
|
- | 149 | method = IPC_GET_METHOD(pcall->question); |
|
- | 150 | retval = IPC_GET_RETVAL(*answer); |
|
- | 151 | printf("phone=%d, method=%d, retval=%d\n", |
|
- | 152 | phone, method, retval); |
|
- | 153 | ||
- | 154 | if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
|
- | 155 | /* Connected to a service (through NS) */ |
|
- | 156 | cphone = IPC_GET_ARG5(*answer); |
|
- | 157 | printf("registering connection (phone %d)\n", cphone); |
|
- | 158 | connection_set(cphone, 0, &proto); |
|
- | 159 | } else { |
|
- | 160 | printf("unrecognized connection\n"); |
|
- | 161 | } |
|
- | 162 | } |
|
- | 163 | ||
130 | void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash) |
164 | void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash) |
131 | { |
165 | { |
132 | link_t *item; |
166 | link_t *item; |
133 | pending_call_t *pcall; |
167 | pending_call_t *pcall; |
134 | 168 | ||
Line 141... | Line 175... | ||
141 | IPC_GET_ARG3(*call), |
175 | IPC_GET_ARG3(*call), |
142 | IPC_GET_ARG4(*call), |
176 | IPC_GET_ARG4(*call), |
143 | IPC_GET_ARG5(*call) |
177 | IPC_GET_ARG5(*call) |
144 | );*/ |
178 | );*/ |
145 | 179 | ||
146 | if ((hash & IPC_CALLID_ANSWERED) == 0) { |
180 | if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) { |
147 | /* Not a response */ |
181 | /* Not a response */ |
148 | printf("Not a response\n"); |
182 | printf("Not a response (hash %d)\n", hash); |
149 | return; |
183 | return; |
150 | } |
184 | } |
151 | 185 | ||
152 | hash = hash & ~IPC_CALLID_ANSWERED; |
186 | hash = hash & ~IPC_CALLID_ANSWERED; |
153 | 187 | ||
Line 156... | Line 190... | ||
156 | 190 | ||
157 | pcall = hash_table_get_instance(item, pending_call_t, link); |
191 | pcall = hash_table_get_instance(item, pending_call_t, link); |
158 | 192 | ||
159 | printf("response matched to question\n"); |
193 | printf("response matched to question\n"); |
160 | hash_table_remove(&pending_calls, &hash, 1); |
194 | hash_table_remove(&pending_calls, &hash, 1); |
- | 195 | ||
- | 196 | parse_answer(pcall, call); |
|
- | 197 | free(pcall); |
|
161 | } |
198 | } |
162 | 199 | ||
163 | void ipcp_call_sync(int phone, ipc_call_t *call, ipc_call_t *answer) |
200 | void ipcp_call_sync(int phone, ipc_call_t *call, ipc_call_t *answer) |
164 | { |
201 | { |
165 | ipcp_call_out(phone, call, 0); |
202 | ipcp_call_out(phone, call, IPCP_CALLID_SYNC); |
166 | ipcp_call_in(answer, 0); |
203 | ipcp_call_in(answer, IPCP_CALLID_SYNC); |
167 | } |
204 | } |
168 | 205 | ||
169 | void ipcp_hangup(int phone, int rc) |
206 | void ipcp_hangup(int phone, int rc) |
170 | { |
207 | { |
171 | printf("hangup phone %d -> %d\n", phone, rc); |
208 | printf("hangup phone %d -> %d\n", phone, rc); |
- | 209 | connection_clear(phone); |
|
172 | } |
210 | } |
173 | 211 | ||
174 | /** @} |
212 | /** @} |
175 | */ |
213 | */ |