Changes in uspace/lib/c/generic/iplink.c [02a09ed:ffa8912] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/iplink.c
r02a09ed rffa8912 39 39 #include <errno.h> 40 40 #include <inet/iplink.h> 41 #include <inet/addr.h>42 41 #include <ipc/iplink.h> 43 42 #include <ipc/services.h> … … 50 49 iplink_t **riplink) 51 50 { 52 iplink_t *iplink = calloc(1, sizeof(iplink_t)); 51 iplink_t *iplink = NULL; 52 int rc; 53 54 iplink = calloc(1, sizeof(iplink_t)); 53 55 if (iplink == NULL) 54 56 return ENOMEM; 55 57 56 58 iplink->sess = sess; 57 59 iplink->ev_ops = ev_ops; 58 60 59 61 async_exch_t *exch = async_exchange_begin(sess); 60 61 intrc = async_connect_to_me(exch, 0, 0, 0, iplink_cb_conn, iplink);62 63 rc = async_connect_to_me(exch, 0, 0, 0, iplink_cb_conn, iplink); 62 64 async_exchange_end(exch); 63 65 64 66 if (rc != EOK) 65 67 goto error; 66 68 67 69 *riplink = iplink; 68 70 return EOK; 69 71 70 72 error: 71 73 if (iplink != NULL) 72 74 free(iplink); 73 75 74 76 return rc; 75 77 } … … 84 86 { 85 87 async_exch_t *exch = async_exchange_begin(iplink->sess); 86 88 87 89 ipc_call_t answer; 88 aid_t req = async_send_0(exch, IPLINK_SEND, &answer); 89 90 int rc = async_data_write_start(exch, &sdu->src, sizeof(inet_addr_t)); 90 aid_t req = async_send_2(exch, IPLINK_SEND, sdu->lsrc.ipv4, 91 sdu->ldest.ipv4, &answer); 92 int rc = async_data_write_start(exch, sdu->data, sdu->size); 93 async_exchange_end(exch); 94 91 95 if (rc != EOK) { 92 async_exchange_end(exch); 93 async_forget(req); 96 async_wait_for(req, NULL); 94 97 return rc; 95 98 } 96 97 rc = async_data_write_start(exch, &sdu->dest, sizeof(inet_addr_t)); 98 if (rc != EOK) { 99 async_exchange_end(exch); 100 async_forget(req); 101 return rc; 102 } 103 104 rc = async_data_write_start(exch, sdu->data, sdu->size); 105 106 async_exchange_end(exch); 107 108 if (rc != EOK) { 109 async_forget(req); 110 return rc; 111 } 112 99 113 100 sysarg_t retval; 114 101 async_wait_for(req, &retval); 115 116 return (int) retval; 102 if (retval != EOK) 103 return retval; 104 105 return EOK; 117 106 } 118 107 … … 132 121 } 133 122 134 int iplink_addr_add(iplink_t *iplink, i net_addr_t *addr)123 int iplink_addr_add(iplink_t *iplink, iplink_addr_t *addr) 135 124 { 136 125 async_exch_t *exch = async_exchange_begin(iplink->sess); 137 138 ipc_call_t answer; 139 aid_t req = async_send_0(exch, IPLINK_ADDR_ADD, &answer); 140 141 int rc = async_data_write_start(exch, addr, sizeof(inet_addr_t)); 126 127 int rc = async_req_1_0(exch, IPLINK_ADDR_ADD, (sysarg_t)addr->ipv4); 142 128 async_exchange_end(exch); 143 144 if (rc != EOK) { 145 async_forget(req); 146 return rc; 147 } 148 149 sysarg_t retval; 150 async_wait_for(req, &retval); 151 152 return (int) retval; 129 130 return rc; 153 131 } 154 132 155 int iplink_addr_remove(iplink_t *iplink, i net_addr_t *addr)133 int iplink_addr_remove(iplink_t *iplink, iplink_addr_t *addr) 156 134 { 157 135 async_exch_t *exch = async_exchange_begin(iplink->sess); 158 159 ipc_call_t answer; 160 aid_t req = async_send_0(exch, IPLINK_ADDR_REMOVE, &answer); 161 162 int rc = async_data_write_start(exch, addr, sizeof(inet_addr_t)); 136 137 int rc = async_req_1_0(exch, IPLINK_ADDR_REMOVE, (sysarg_t)addr->ipv4); 163 138 async_exchange_end(exch); 164 165 if (rc != EOK) { 166 async_forget(req); 167 return rc; 168 } 169 170 sysarg_t retval; 171 async_wait_for(req, &retval); 172 173 return (int) retval; 139 140 return rc; 174 141 } 175 142 176 static void iplink_ev_recv(iplink_t *iplink, ipc_callid_t iid,177 ipc_call_t * icall)143 static void iplink_ev_recv(iplink_t *iplink, ipc_callid_t callid, 144 ipc_call_t *call) 178 145 { 179 iplink_recv_sdu_t sdu; 180 181 uint16_t af = IPC_GET_ARG1(*icall); 182 183 int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, 184 &sdu.size); 146 int rc; 147 iplink_sdu_t sdu; 148 149 sdu.lsrc.ipv4 = IPC_GET_ARG1(*call); 150 sdu.ldest.ipv4 = IPC_GET_ARG2(*call); 151 152 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 185 153 if (rc != EOK) { 186 async_answer_0( iid, rc);154 async_answer_0(callid, rc); 187 155 return; 188 156 } 189 190 rc = iplink->ev_ops->recv(iplink, &sdu , af);157 158 rc = iplink->ev_ops->recv(iplink, &sdu); 191 159 free(sdu.data); 192 async_answer_0( iid, rc);160 async_answer_0(callid, rc); 193 161 } 194 162 195 163 static void iplink_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 196 164 { 197 iplink_t *iplink = (iplink_t *) 198 165 iplink_t *iplink = (iplink_t *)arg; 166 199 167 while (true) { 200 168 ipc_call_t call; 201 169 ipc_callid_t callid = async_get_call(&call); 202 170 203 171 if (!IPC_GET_IMETHOD(call)) { 204 172 /* TODO: Handle hangup */ 205 173 return; 206 174 } 207 175 208 176 switch (IPC_GET_IMETHOD(call)) { 209 177 case IPLINK_EV_RECV:
Note:
See TracChangeset
for help on using the changeset viewer.