Changeset b5e68c8 in mainline for uspace/lib/net/tl/tl_common.c


Ignore:
Timestamp:
2011-05-12T16:49:44Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f36787d7
Parents:
e80329d6 (diff), 750636a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    re80329d6 rb5e68c8  
    2727 */
    2828
    29 /** @addtogroup libnet 
     29/** @addtogroup libnet
    3030 * @{
    3131 */
     
    3939#include <packet_client.h>
    4040#include <packet_remote.h>
    41 #include <icmp_interface.h>
     41#include <icmp_remote.h>
    4242#include <ip_remote.h>
    4343#include <ip_interface.h>
    44 #include <tl_interface.h>
     44#include <tl_remote.h>
    4545
    4646#include <net/socket_codes.h>
     
    5454#include <ipc/services.h>
    5555#include <errno.h>
    56 #include <err.h>
    5756
    5857DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
     
    6564 * @param[in] addrlen   The address length.
    6665 * @param[out] port     The set port.
    67  * @returns             EOK on success.
    68  * @returns             EINVAL if the address length does not match the address
     66 * @return              EOK on success.
     67 * @return              EINVAL if the address length does not match the address
    6968 *                      family.
    70  * @returns             EAFNOSUPPORT if the address family is not supported.
     69 * @return              EAFNOSUPPORT if the address family is not supported.
    7170 */
    7271int
     
    121120int
    122121tl_get_ip_packet_dimension(int ip_phone,
    123     packet_dimensions_ref packet_dimensions, device_id_t device_id,
    124     packet_dimension_ref *packet_dimension)
    125 {
    126         ERROR_DECLARE;
     122    packet_dimensions_t *packet_dimensions, device_id_t device_id,
     123    packet_dimension_t **packet_dimension)
     124{
     125        int rc;
    127126       
    128127        if (!packet_dimension)
     
    137136                        return ENOMEM;
    138137               
    139                 if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
    140                     *packet_dimension))) {
     138                rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
     139                if (rc != EOK) {
    141140                        free(*packet_dimension);
    142                         return ERROR_CODE;
     141                        return rc;
    143142                }
    144143               
    145                 ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
     144                rc = packet_dimensions_add(packet_dimensions, device_id,
    146145                    *packet_dimension);
    147                 if (ERROR_CODE < 0) {
     146                if (rc < 0) {
    148147                        free(*packet_dimension);
    149                         return ERROR_CODE;
     148                        return rc;
    150149                }
    151150        }
     
    159158 * @param[in] device_id The device identifier.
    160159 * @param[in] content   The new maximum content size.
    161  * @returns             EOK on success.
     160 * @return              EOK on success.
    162161 * @return              ENOENT if the packet dimension is not cached.
    163162 */
    164163int
    165 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
     164tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions,
    166165    device_id_t device_id, size_t content)
    167166{
    168         packet_dimension_ref packet_dimension;
     167        packet_dimension_t *packet_dimension;
    169168
    170169        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
     
    183182                        else
    184183                                packet_dimensions_exclude(packet_dimensions,
    185                                     DEVICE_INVALID_ID);
     184                                    DEVICE_INVALID_ID, free);
    186185                }
    187186        }
     
    197196 * @param[in] addrlen   The address length.
    198197 * @param[in] port      The port to be set.
    199  * @returns             EOK on success.
    200  * @returns             EINVAL if the address length does not match the address
     198 * @return              EOK on success.
     199 * @return              EINVAL if the address length does not match the address
    201200 *                      family.
    202  * @returns             EAFNOSUPPORT if the address family is not supported.
     201 * @return              EAFNOSUPPORT if the address family is not supported.
    203202 */
    204203int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
     
    245244 * @param[in] error     The packet error reporting service. Prefixes the
    246245 *                      received packet.
    247  * @returns             EOK on success.
    248  * @returns             ENOENT if no packet may be sent.
    249  */
    250 int
    251 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t 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,
    252251    services_t error)
    253252{
    254         packet_t next;
     253        packet_t *next;
    255254        uint8_t *src;
    256255        int length;
    257256
    258         // detach the first packet and release the others
     257        /* Detach the first packet and release the others */
    259258        next = pq_detach(packet);
    260259        if (next)
     
    263262        length = packet_get_addr(packet, &src, NULL);
    264263        if ((length > 0) && (!error) && (icmp_phone >= 0) &&
    265             // set both addresses to the source one (avoids the source address
    266             // deletion before setting the destination one)
     264            /*
     265             * Set both addresses to the source one (avoids the source address
     266             * deletion before setting the destination one)
     267             */
    267268            (packet_set_addr(packet, src, src, (size_t) length) == EOK)) {
    268269                return EOK;
     
    281282 * @param[in] addr      The destination address.
    282283 * @param[in] addrlen   The address length.
    283  * @returns             Number of bytes received.
    284  * @returns             EINVAL if the client does not send data.
    285  * @returns             ENOMEM if there is not enough memory left.
    286  * @returns             Other error codes as defined for the
     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
    287288 *                      async_data_read_finalize() function.
    288289 */
    289290int
    290 tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix,
    291     const packet_dimension_ref dimension, const struct sockaddr *addr,
     291tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix,
     292    const packet_dimension_t *dimension, const struct sockaddr *addr,
    292293    socklen_t addrlen)
    293294{
    294         ERROR_DECLARE;
    295 
    296295        ipc_callid_t callid;
    297296        size_t length;
    298         void * data;
     297        void *data;
     298        int rc;
    299299
    300300        if (!dimension)
    301301                return EINVAL;
    302302
    303         // get the data length
     303        /* Get the data length */
    304304        if (!async_data_write_receive(&callid, &length))
    305305                return EINVAL;
    306306
    307         // get a new packet
     307        /* Get a new packet */
    308308        *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len,
    309309            prefix + dimension->prefix, dimension->suffix);
     
    311311                return ENOMEM;
    312312
    313         // allocate space in the packet
     313        /* Allocate space in the packet */
    314314        data = packet_suffix(*packet, length);
    315315        if (!data) {
     
    318318        }
    319319
    320         // read the data into the packet
    321         if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) ||
    322             // set the packet destination address
    323             ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr,
    324             addrlen))) {
     320        /* Read the data into the packet */
     321        rc = async_data_write_finalize(callid, data, length);
     322        if (rc != EOK) {
    325323                pq_release_remote(packet_phone, packet_get_id(*packet));
    326                 return ERROR_CODE;
     324                return rc;
     325        }
     326       
     327        /* Set the packet destination address */
     328        rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
     329        if (rc != EOK) {
     330                pq_release_remote(packet_phone, packet_get_id(*packet));
     331                return rc;
    327332        }
    328333
Note: See TracChangeset for help on using the changeset viewer.