Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/tl/tl_common.c

    r28a3e74 r609243f4  
    4343#include <ip_interface.h>
    4444#include <tl_remote.h>
    45 
    4645#include <net/socket_codes.h>
    4746#include <net/in.h>
     
    5049#include <net/device.h>
    5150#include <net/packet.h>
    52 
    5351#include <async.h>
    5452#include <ipc/services.h>
     
    107105 * The reply is cached then.
    108106 *
    109  * @param[in] ip_phone  The IP moduel phone for (semi)remote calls.
    110  * @param[in] packet_dimensions The packet dimensions cache.
    111  * @param[in] device_id The device identifier.
    112  * @param[out] packet_dimension The IP packet dimensions.
    113  * @return              EOK on success.
    114  * @return              EBADMEM if the packet_dimension parameter is NULL.
    115  * @return              ENOMEM if there is not enough memory left.
    116  * @return              EINVAL if the packet_dimensions cache is not valid.
    117  * @return              Other codes as defined for the ip_packet_size_req()
    118  *                      function.
    119  */
    120 int
    121 tl_get_ip_packet_dimension(int ip_phone,
    122     packet_dimensions_t *packet_dimensions, device_id_t device_id,
     107 * @param[in]  sess              IP module session.
     108 * @param[in]  packet_dimensions Packet dimensions cache.
     109 * @param[in]  device_id         Device identifier.
     110 * @param[out] packet_dimension  IP packet dimensions.
     111 *
     112 * @return EOK on success.
     113 * @return EBADMEM if the packet_dimension parameter is NULL.
     114 * @return ENOMEM if there is not enough memory left.
     115 * @return EINVAL if the packet_dimensions cache is not valid.
     116 * @return Other codes as defined for the ip_packet_size_req()
     117 *         function.
     118 *
     119 */
     120int tl_get_ip_packet_dimension(async_sess_t *sess,
     121    packet_dimensions_t *packet_dimensions, nic_device_id_t device_id,
    123122    packet_dimension_t **packet_dimension)
    124123{
    125         int rc;
    126        
    127124        if (!packet_dimension)
    128125                return EBADMEM;
     
    133130                /* Ask for and remember them if not found */
    134131                *packet_dimension = malloc(sizeof(**packet_dimension));
    135                 if(!*packet_dimension)
     132                if (!*packet_dimension)
    136133                        return ENOMEM;
    137134               
    138                 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
     135                int rc = ip_packet_size_req(sess, device_id, *packet_dimension);
    139136                if (rc != EOK) {
    140137                        free(*packet_dimension);
     
    163160int
    164161tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions,
    165     device_id_t device_id, size_t content)
     162    nic_device_id_t device_id, size_t content)
    166163{
    167164        packet_dimension_t *packet_dimension;
     
    173170        packet_dimension->content = content;
    174171
    175         if (device_id != DEVICE_INVALID_ID) {
     172        if (device_id != NIC_DEVICE_INVALID_ID) {
    176173                packet_dimension = packet_dimensions_find(packet_dimensions,
    177                     DEVICE_INVALID_ID);
     174                    NIC_DEVICE_INVALID_ID);
    178175
    179176                if (packet_dimension) {
     
    182179                        else
    183180                                packet_dimensions_exclude(packet_dimensions,
    184                                     DEVICE_INVALID_ID, free);
     181                                    NIC_DEVICE_INVALID_ID, free);
    185182                }
    186183        }
     
    236233/** Prepares the packet for ICMP error notification.
    237234 *
    238  * Keeps the first packet and releases all the others.
    239  * Releases all the packets on error.
    240  *
    241  * @param[in] packet_phone The packet server module phone.
    242  * @param[in] icmp_phone The ICMP module phone.
    243  * @param[in] packet    The packet to be send.
    244  * @param[in] error     The packet error reporting service. Prefixes the
    245  *                      received packet.
    246  * @return              EOK on success.
    247  * @return              ENOENT if no packet may be sent.
    248  */
    249 int
    250 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet,
    251     services_t error)
    252 {
    253         packet_t *next;
     235 * Keep the first packet and release all the others.
     236 * Release all the packets on error.
     237 *
     238 * @param[in] packet_sess Packet server module session.
     239 * @param[in] icmp_sess   ICMP module phone.
     240 * @param[in] packet      Packet to be send.
     241 * @param[in] error       Packet error reporting service. Prefixes the
     242 *                        received packet.
     243 *
     244 * @return EOK on success.
     245 * @return ENOENT if no packet may be sent.
     246 *
     247 */
     248int tl_prepare_icmp_packet(async_sess_t *packet_sess, async_sess_t *icmp_sess,
     249    packet_t *packet, services_t error)
     250{
     251        /* Detach the first packet and release the others */
     252        packet_t *next = pq_detach(packet);
     253        if (next)
     254                pq_release_remote(packet_sess, packet_get_id(next));
     255       
    254256        uint8_t *src;
    255         int length;
    256 
    257         /* Detach the first packet and release the others */
    258         next = pq_detach(packet);
    259         if (next)
    260                 pq_release_remote(packet_phone, packet_get_id(next));
    261        
    262         length = packet_get_addr(packet, &src, NULL);
    263         if ((length > 0) && (!error) && (icmp_phone >= 0) &&
     257        int length = packet_get_addr(packet, &src, NULL);
     258        if ((length > 0) && (!error) && (icmp_sess) &&
    264259            /*
    265260             * Set both addresses to the source one (avoids the source address
     
    269264                return EOK;
    270265        } else
    271                 pq_release_remote(packet_phone, packet_get_id(packet));
    272 
     266                pq_release_remote(packet_sess, packet_get_id(packet));
     267       
    273268        return ENOENT;
    274269}
     
    276271/** Receives data from the socket into a packet.
    277272 *
    278  * @param[in] packet_phone The packet server module phone.
    279  * @param[out] packet   The new created packet.
    280  * @param[in] prefix    Reserved packet data prefix length.
    281  * @param[in] dimension The packet dimension.
    282  * @param[in] addr      The destination address.
    283  * @param[in] addrlen   The address length.
    284  * @return              Number of bytes received.
    285  * @return              EINVAL if the client does not send data.
    286  * @return              ENOMEM if there is not enough memory left.
    287  * @return              Other error codes as defined for the
    288  *                      async_data_read_finalize() function.
    289  */
    290 int
    291 tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix,
    292     const packet_dimension_t *dimension, const struct sockaddr *addr,
    293     socklen_t addrlen)
     273 * @param[in]  sess      Packet server module session.
     274 * @param[out] packet    New created packet.
     275 * @param[in]  prefix    Reserved packet data prefix length.
     276 * @param[in]  dimension Packet dimension.
     277 * @param[in]  addr      Destination address.
     278 * @param[in]  addrlen   Address length.
     279 *
     280 * @return Number of bytes received.
     281 * @return EINVAL if the client does not send data.
     282 * @return ENOMEM if there is not enough memory left.
     283 * @return Other error codes as defined for the
     284 *         async_data_read_finalize() function.
     285 *
     286 */
     287int tl_socket_read_packet_data(async_sess_t *sess, packet_t **packet,
     288    size_t prefix, const packet_dimension_t *dimension,
     289    const struct sockaddr *addr, socklen_t addrlen)
    294290{
    295291        ipc_callid_t callid;
     
    306302
    307303        /* Get a new packet */
    308         *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len,
     304        *packet = packet_get_4_remote(sess, length, dimension->addr_len,
    309305            prefix + dimension->prefix, dimension->suffix);
    310306        if (!packet)
     
    314310        data = packet_suffix(*packet, length);
    315311        if (!data) {
    316                 pq_release_remote(packet_phone, packet_get_id(*packet));
     312                pq_release_remote(sess, packet_get_id(*packet));
    317313                return ENOMEM;
    318314        }
     
    321317        rc = async_data_write_finalize(callid, data, length);
    322318        if (rc != EOK) {
    323                 pq_release_remote(packet_phone, packet_get_id(*packet));
     319                pq_release_remote(sess, packet_get_id(*packet));
    324320                return rc;
    325321        }
     
    328324        rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
    329325        if (rc != EOK) {
    330                 pq_release_remote(packet_phone, packet_get_id(*packet));
     326                pq_release_remote(sess, packet_get_id(*packet));
    331327                return rc;
    332328        }
Note: See TracChangeset for help on using the changeset viewer.