Ignore:
File:
1 edited

Legend:

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

    r6b82009 r28a3e74  
    4343#include <ip_interface.h>
    4444#include <tl_remote.h>
     45
    4546#include <net/socket_codes.h>
    4647#include <net/in.h>
     
    4950#include <net/device.h>
    5051#include <net/packet.h>
     52
    5153#include <async.h>
    5254#include <ipc/services.h>
     
    105107 * The reply is cached then.
    106108 *
    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  */
    120 int tl_get_ip_packet_dimension(async_sess_t *sess,
     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 */
     120int
     121tl_get_ip_packet_dimension(int ip_phone,
    121122    packet_dimensions_t *packet_dimensions, device_id_t device_id,
    122123    packet_dimension_t **packet_dimension)
    123124{
     125        int rc;
     126       
    124127        if (!packet_dimension)
    125128                return EBADMEM;
     
    130133                /* Ask for and remember them if not found */
    131134                *packet_dimension = malloc(sizeof(**packet_dimension));
    132                 if (!*packet_dimension)
     135                if(!*packet_dimension)
    133136                        return ENOMEM;
    134137               
    135                 int rc = ip_packet_size_req(sess, device_id, *packet_dimension);
     138                rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
    136139                if (rc != EOK) {
    137140                        free(*packet_dimension);
     
    233236/** Prepares the packet for ICMP error notification.
    234237 *
    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  */
    248 int tl_prepare_icmp_packet(async_sess_t *packet_sess, async_sess_t *icmp_sess,
    249     packet_t *packet, services_t error)
    250 {
     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 */
     249int
     250tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet,
     251    services_t error)
     252{
     253        packet_t *next;
     254        uint8_t *src;
     255        int length;
     256
    251257        /* Detach the first packet and release the others */
    252         packet_t *next = pq_detach(packet);
     258        next = pq_detach(packet);
    253259        if (next)
    254                 pq_release_remote(packet_sess, packet_get_id(next));
    255        
    256         uint8_t *src;
    257         int length = packet_get_addr(packet, &src, NULL);
    258         if ((length > 0) && (!error) && (icmp_sess) &&
     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) &&
    259264            /*
    260265             * Set both addresses to the source one (avoids the source address
     
    264269                return EOK;
    265270        } else
    266                 pq_release_remote(packet_sess, packet_get_id(packet));
    267        
     271                pq_release_remote(packet_phone, packet_get_id(packet));
     272
    268273        return ENOENT;
    269274}
     
    271276/** Receives data from the socket into a packet.
    272277 *
    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  */
    287 int 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)
     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 */
     290int
     291tl_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)
    290294{
    291295        ipc_callid_t callid;
     
    302306
    303307        /* Get a new packet */
    304         *packet = packet_get_4_remote(sess, length, dimension->addr_len,
     308        *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len,
    305309            prefix + dimension->prefix, dimension->suffix);
    306310        if (!packet)
     
    310314        data = packet_suffix(*packet, length);
    311315        if (!data) {
    312                 pq_release_remote(sess, packet_get_id(*packet));
     316                pq_release_remote(packet_phone, packet_get_id(*packet));
    313317                return ENOMEM;
    314318        }
     
    317321        rc = async_data_write_finalize(callid, data, length);
    318322        if (rc != EOK) {
    319                 pq_release_remote(sess, packet_get_id(*packet));
     323                pq_release_remote(packet_phone, packet_get_id(*packet));
    320324                return rc;
    321325        }
     
    324328        rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
    325329        if (rc != EOK) {
    326                 pq_release_remote(sess, packet_get_id(*packet));
     330                pq_release_remote(packet_phone, packet_get_id(*packet));
    327331                return rc;
    328332        }
Note: See TracChangeset for help on using the changeset viewer.