Ignore:
File:
1 edited

Legend:

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

    rbd8bfc5a rd8b47eca  
    3030#include <assert.h>
    3131#include <errno.h>
     32#include <net/socket_codes.h>
    3233#include <inet/inet.h>
    3334#include <ipc/inet.h>
     
    4445{
    4546        async_exch_t *exch = async_exchange_begin(inet_sess);
    46 
     47       
    4748        ipc_call_t answer;
    4849        aid_t req = async_send_0(exch, INET_CALLBACK_CREATE, &answer);
    4950        int rc = async_connect_to_me(exch, 0, 0, 0, inet_cb_conn, NULL);
    5051        async_exchange_end(exch);
    51 
     52       
    5253        if (rc != EOK)
    5354                return rc;
    54 
     55       
    5556        sysarg_t retval;
    5657        async_wait_for(req, &retval);
    57         if (retval != EOK)
    58                 return retval;
    59 
    60         return EOK;
     58       
     59        return retval;
    6160}
    6261
    6362static int inet_set_proto(uint8_t protocol)
    6463{
    65         int rc;
    66 
    67         async_exch_t *exch = async_exchange_begin(inet_sess);
    68         rc = async_req_1_0(exch, INET_SET_PROTO, protocol);
    69         async_exchange_end(exch);
    70 
     64        async_exch_t *exch = async_exchange_begin(inet_sess);
     65        int rc = async_req_1_0(exch, INET_SET_PROTO, protocol);
     66        async_exchange_end(exch);
     67       
    7168        return rc;
    7269}
     
    8077        assert(inet_ev_ops == NULL);
    8178        assert(inet_protocol == 0);
    82 
     79       
    8380        rc = loc_service_get_id(SERVICE_NAME_INET, &inet_svc,
    8481            IPC_FLAG_BLOCKING);
    8582        if (rc != EOK)
    8683                return ENOENT;
    87 
     84       
    8885        inet_sess = loc_service_connect(EXCHANGE_SERIALIZE, inet_svc,
    8986            IPC_FLAG_BLOCKING);
    9087        if (inet_sess == NULL)
    9188                return ENOENT;
    92 
     89       
    9390        if (inet_set_proto(protocol) != EOK) {
    9491                async_hangup(inet_sess);
     
    9693                return EIO;
    9794        }
    98 
     95       
    9996        if (inet_callback_create() != EOK) {
    10097                async_hangup(inet_sess);
     
    10299                return EIO;
    103100        }
    104 
     101       
    105102        inet_protocol = protocol;
    106103        inet_ev_ops = ev_ops;
     
    112109{
    113110        async_exch_t *exch = async_exchange_begin(inet_sess);
    114 
     111       
    115112        ipc_call_t answer;
    116         aid_t req = async_send_5(exch, INET_SEND, dgram->src.ipv4,
    117             dgram->dest.ipv4, dgram->tos, ttl, df, &answer);
    118         int rc = async_data_write_start(exch, dgram->data, dgram->size);
    119         async_exchange_end(exch);
    120 
    121         if (rc != EOK) {
    122                 async_wait_for(req, NULL);
    123                 return rc;
    124         }
    125 
     113        aid_t req = async_send_3(exch, INET_SEND, dgram->tos, ttl, df,
     114            &answer);
     115       
     116        int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
     117        if (rc != EOK) {
     118                async_exchange_end(exch);
     119                async_forget(req);
     120                return rc;
     121        }
     122       
     123        rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
     124        if (rc != EOK) {
     125                async_exchange_end(exch);
     126                async_forget(req);
     127                return rc;
     128        }
     129       
     130        rc = async_data_write_start(exch, dgram->data, dgram->size);
     131       
     132        async_exchange_end(exch);
     133       
     134        if (rc != EOK) {
     135                async_forget(req);
     136                return rc;
     137        }
     138       
    126139        sysarg_t retval;
    127140        async_wait_for(req, &retval);
    128         if (retval != EOK)
    129                 return retval;
    130 
    131         return EOK;
     141       
     142        return (int) retval;
    132143}
    133144
    134145int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local)
    135146{
    136         sysarg_t local_addr;
    137         async_exch_t *exch = async_exchange_begin(inet_sess);
    138 
    139         int rc = async_req_2_1(exch, INET_GET_SRCADDR, remote->ipv4,
    140             tos, &local_addr);
    141         async_exchange_end(exch);
    142 
    143         if (rc != EOK)
    144                 return rc;
    145 
    146         local->ipv4 = local_addr;
    147         return EOK;
    148 }
    149 
    150 static void inet_ev_recv(ipc_callid_t callid, ipc_call_t *call)
    151 {
    152         int rc;
     147        async_exch_t *exch = async_exchange_begin(inet_sess);
     148       
     149        ipc_call_t answer;
     150        aid_t req = async_send_1(exch, INET_GET_SRCADDR, tos, &answer);
     151       
     152        int rc = async_data_write_start(exch, remote, sizeof(inet_addr_t));
     153        if (rc != EOK) {
     154                async_exchange_end(exch);
     155                async_forget(req);
     156                return rc;
     157        }
     158       
     159        rc = async_data_read_start(exch, local, sizeof(inet_addr_t));
     160       
     161        async_exchange_end(exch);
     162       
     163        if (rc != EOK) {
     164                async_forget(req);
     165                return rc;
     166        }
     167       
     168        sysarg_t retval;
     169        async_wait_for(req, &retval);
     170       
     171        return (int) retval;
     172}
     173
     174static void inet_ev_recv(ipc_callid_t iid, ipc_call_t *icall)
     175{
    153176        inet_dgram_t dgram;
    154 
    155         dgram.src.ipv4 = IPC_GET_ARG1(*call);
    156         dgram.dest.ipv4 = IPC_GET_ARG2(*call);
    157         dgram.tos = IPC_GET_ARG3(*call);
    158 
     177       
     178        dgram.tos = IPC_GET_ARG1(*icall);
     179       
     180        ipc_callid_t callid;
     181        size_t size;
     182        if (!async_data_write_receive(&callid, &size)) {
     183                async_answer_0(callid, EINVAL);
     184                async_answer_0(iid, EINVAL);
     185                return;
     186        }
     187       
     188        if (size != sizeof(inet_addr_t)) {
     189                async_answer_0(callid, EINVAL);
     190                async_answer_0(iid, EINVAL);
     191                return;
     192        }
     193       
     194        int rc = async_data_write_finalize(callid, &dgram.src, size);
     195        if (rc != EOK) {
     196                async_answer_0(callid, rc);
     197                async_answer_0(iid, rc);
     198                return;
     199        }
     200       
     201        if (!async_data_write_receive(&callid, &size)) {
     202                async_answer_0(callid, EINVAL);
     203                async_answer_0(iid, EINVAL);
     204                return;
     205        }
     206       
     207        if (size != sizeof(inet_addr_t)) {
     208                async_answer_0(callid, EINVAL);
     209                async_answer_0(iid, EINVAL);
     210                return;
     211        }
     212       
     213        rc = async_data_write_finalize(callid, &dgram.dest, size);
     214        if (rc != EOK) {
     215                async_answer_0(callid, rc);
     216                async_answer_0(iid, rc);
     217                return;
     218        }
     219       
    159220        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
    160221        if (rc != EOK) {
    161                 async_answer_0(callid, rc);
    162                 return;
    163         }
    164 
     222                async_answer_0(iid, rc);
     223                return;
     224        }
     225       
    165226        rc = inet_ev_ops->recv(&dgram);
    166         async_answer_0(callid, rc);
     227        async_answer_0(iid, rc);
    167228}
    168229
     
    172233                ipc_call_t call;
    173234                ipc_callid_t callid = async_get_call(&call);
    174 
     235               
    175236                if (!IPC_GET_IMETHOD(call)) {
    176237                        /* TODO: Handle hangup */
    177238                        return;
    178239                }
    179 
     240               
    180241                switch (IPC_GET_IMETHOD(call)) {
    181242                case INET_EV_RECV:
Note: See TracChangeset for help on using the changeset viewer.