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