Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/iplink.c

    r77ad86c r02a09ed  
    3939#include <errno.h>
    4040#include <inet/iplink.h>
     41#include <inet/addr.h>
    4142#include <ipc/iplink.h>
    4243#include <ipc/services.h>
     
    8384{
    8485        async_exch_t *exch = async_exchange_begin(iplink->sess);
    85 
     86       
    8687        ipc_call_t answer;
    87         aid_t req = async_send_2(exch, IPLINK_SEND, sdu->lsrc.ipv4,
    88             sdu->ldest.ipv4, &answer);
    89         int rc = async_data_write_start(exch, sdu->data, sdu->size);
    90         async_exchange_end(exch);
    91 
    92         if (rc != EOK) {
    93                 async_forget(req);
    94                 return rc;
    95         }
    96 
     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       
    97113        sysarg_t retval;
    98114        async_wait_for(req, &retval);
    99         if (retval != EOK)
    100                 return retval;
    101 
    102         return EOK;
     115       
     116        return (int) retval;
    103117}
    104118
     
    118132}
    119133
    120 int iplink_addr_add(iplink_t *iplink, iplink_addr_t *addr)
    121 {
    122         async_exch_t *exch = async_exchange_begin(iplink->sess);
    123 
    124         int rc = async_req_1_0(exch, IPLINK_ADDR_ADD, (sysarg_t)addr->ipv4);
    125         async_exchange_end(exch);
    126 
    127         return rc;
    128 }
    129 
    130 int iplink_addr_remove(iplink_t *iplink, iplink_addr_t *addr)
    131 {
    132         async_exch_t *exch = async_exchange_begin(iplink->sess);
    133 
    134         int rc = async_req_1_0(exch, IPLINK_ADDR_REMOVE, (sysarg_t)addr->ipv4);
    135         async_exchange_end(exch);
    136 
    137         return rc;
    138 }
    139 
    140 static void iplink_ev_recv(iplink_t *iplink, ipc_callid_t callid,
    141     ipc_call_t *call)
    142 {
    143         int rc;
    144         iplink_sdu_t sdu;
    145 
    146         sdu.lsrc.ipv4 = IPC_GET_ARG1(*call);
    147         sdu.ldest.ipv4 = IPC_GET_ARG2(*call);
    148 
    149         rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size);
    150         if (rc != EOK) {
    151                 async_answer_0(callid, rc);
     134int 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
     155int 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
     176static 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);
    152187                return;
    153188        }
    154 
    155         rc = iplink->ev_ops->recv(iplink, &sdu);
     189       
     190        rc = iplink->ev_ops->recv(iplink, &sdu, af);
    156191        free(sdu.data);
    157         async_answer_0(callid, rc);
     192        async_answer_0(iid, rc);
    158193}
    159194
    160195static void iplink_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    161196{
    162         iplink_t *iplink = (iplink_t *)arg;
    163 
     197        iplink_t *iplink = (iplink_t *) arg;
     198       
    164199        while (true) {
    165200                ipc_call_t call;
    166201                ipc_callid_t callid = async_get_call(&call);
    167 
     202               
    168203                if (!IPC_GET_IMETHOD(call)) {
    169204                        /* TODO: Handle hangup */
    170205                        return;
    171206                }
    172 
     207               
    173208                switch (IPC_GET_IMETHOD(call)) {
    174209                case IPLINK_EV_RECV:
Note: See TracChangeset for help on using the changeset viewer.