Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/udp/udp.c

    r6092b56e r14f1db0  
    4040#include <malloc.h>
    4141#include <stdio.h>
    42 
    4342#include <ipc/ipc.h>
    4443#include <ipc/services.h>
    4544
    46 #include "../../err.h"
    47 #include "../../messages.h"
    48 #include "../../modules.h"
    49 
    50 #include "../../structures/dynamic_fifo.h"
    51 #include "../../structures/packet/packet_client.h"
    52 
    53 #include "../../include/checksum.h"
    54 #include "../../include/in.h"
    55 #include "../../include/in6.h"
    56 #include "../../include/inet.h"
    57 #include "../../include/ip_client.h"
    58 #include "../../include/ip_interface.h"
    59 #include "../../include/ip_protocols.h"
    60 #include "../../include/icmp_client.h"
    61 #include "../../include/icmp_interface.h"
    62 #include "../../include/net_interface.h"
    63 #include "../../include/socket_codes.h"
    64 #include "../../include/socket_errno.h"
    65 
    66 #include "../../socket/socket_core.h"
    67 #include "../../socket/socket_messages.h"
    68 
    69 #include "../tl_common.h"
    70 #include "../tl_messages.h"
     45#include <net_err.h>
     46#include <net_messages.h>
     47#include <net_modules.h>
     48#include <adt/dynamic_fifo.h>
     49#include <packet/packet_client.h>
     50#include <packet_remote.h>
     51#include <net_checksum.h>
     52#include <in.h>
     53#include <in6.h>
     54#include <inet.h>
     55#include <ip_client.h>
     56#include <ip_interface.h>
     57#include <ip_protocols.h>
     58#include <icmp_client.h>
     59#include <icmp_interface.h>
     60#include <net_interface.h>
     61#include <socket_codes.h>
     62#include <socket_errno.h>
     63#include <socket_core.h>
     64#include <socket_messages.h>
     65#include <tl_common.h>
     66#include <tl_local.h>
     67#include <tl_interface.h>
     68#include <tl_messages.h>
    7169
    7270#include "udp.h"
    7371#include "udp_header.h"
    7472#include "udp_module.h"
     73
     74/** UDP module name.
     75 */
     76#define NAME    "UDP protocol"
    7577
    7678/** Default UDP checksum computing.
     
    259261        icmp_type_t type;
    260262        icmp_code_t code;
    261         ip_pseudo_header_ref ip_header;
     263        void *ip_header;
    262264        struct sockaddr * src;
    263265        struct sockaddr * dest;
     
    357359                        while(tmp_packet){
    358360                                next_packet = pq_detach(tmp_packet);
    359                                 pq_release(udp_globals.net_phone, packet_get_id(tmp_packet));
     361                                pq_release_remote(udp_globals.net_phone, packet_get_id(tmp_packet));
    360362                                tmp_packet = next_packet;
    361363                        }
     
    383385        // queue the received packet
    384386        if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE))
    385                 || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){
     387            || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){
    386388                return udp_release_and_return(packet, ERROR_CODE);
    387389        }
     
    393395}
    394396
    395 int udp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     397int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    396398        ERROR_DECLARE;
    397399
     
    401403        switch(IPC_GET_METHOD(*call)){
    402404                case NET_TL_RECEIVED:
    403                         if(! ERROR_OCCURRED(packet_translate(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     405                        if(! ERROR_OCCURRED(packet_translate_remote(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    404406                                ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_UDP, IPC_GET_ERROR(call));
    405407                        }
     
    419421        int socket_id;
    420422        size_t addrlen;
     423        size_t size;
    421424        ipc_call_t answer;
    422425        int answer_count;
     
    454457                                socket_id = SOCKET_GET_SOCKET_ID(call);
    455458                                res = socket_create(&local_sockets, app_phone, NULL, &socket_id);
    456                                 *SOCKET_SET_SOCKET_ID(answer) = socket_id;
    457                                
     459                                SOCKET_SET_SOCKET_ID(answer, socket_id);
     460
    458461                                if(res == EOK){
    459                                         if(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
    460                                                 *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = packet_dimension->content;
     462                                        if (tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
     463                                                SOCKET_SET_DATA_FRAGMENT_SIZE(answer, packet_dimension->content);
    461464                                        }
    462 //                                      *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_UDP_FRAGMENT_SIZE;
    463                                         *SOCKET_SET_HEADER_SIZE(answer) = UDP_HEADER_SIZE;
     465//                                      SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_UDP_FRAGMENT_SIZE);
     466                                        SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
    464467                                        answer_count = 3;
    465468                                }
     
    478481                                if(res == EOK){
    479482                                        fibril_rwlock_write_lock(&udp_globals.lock);
    480                                         res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
     483                                        res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
     484                                        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    481485                                        if(res != EOK){
    482486                                                fibril_rwlock_write_unlock(&udp_globals.lock);
     
    492496                                fibril_rwlock_write_unlock(&udp_globals.lock);
    493497                                if(res > 0){
    494                                         *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
    495                                         *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
     498                                        SOCKET_SET_READ_DATA_LENGTH(answer, res);
     499                                        SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
    496500                                        answer_count = 3;
    497501                                        res = EOK;
     
    532536        uint16_t dest_port;
    533537        uint32_t checksum;
    534         ip_pseudo_header_ref ip_header;
     538        void *ip_header;
    535539        size_t headerlen;
    536540        device_id_t device_id;
     
    661665                return NO_DATA;
    662666        }
    663         ERROR_PROPAGATE(packet_translate(udp_globals.net_phone, &packet, packet_id));
     667        ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, packet_id));
    664668        // get udp header
    665669        data = packet_get_data(packet);
    666670        if(! data){
    667                 pq_release(udp_globals.net_phone, packet_id);
     671                pq_release_remote(udp_globals.net_phone, packet_id);
    668672                return NO_DATA;
    669673        }
     
    673677        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    674678        if(ERROR_OCCURRED(tl_set_address_port(addr, result, ntohs(header->source_port)))){
    675                 pq_release(udp_globals.net_phone, packet_id);
     679                pq_release_remote(udp_globals.net_phone, packet_id);
    676680                return ERROR_CODE;
    677681        }
     
    688692        // release the packet
    689693        dyn_fifo_pop(&socket->received);
    690         pq_release(udp_globals.net_phone, packet_get_id(packet));
     694        pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
    691695        // return the total length
    692696        return (int) length;
     
    694698
    695699int udp_release_and_return(packet_t packet, int result){
    696         pq_release(udp_globals.net_phone, packet_get_id(packet));
     700        pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
    697701        return result;
    698702}
    699703
     704/** Default thread for new connections.
     705 *
     706 *  @param[in] iid The initial message identifier.
     707 *  @param[in] icall The initial message call structure.
     708 *
     709 */
     710static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     711{
     712        /*
     713         * Accept the connection
     714         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     715         */
     716        ipc_answer_0(iid, EOK);
     717       
     718        while(true) {
     719                ipc_call_t answer;
     720                int answer_count;
     721               
     722                /* Clear the answer structure */
     723                refresh_answer(&answer, &answer_count);
     724               
     725                /* Fetch the next message */
     726                ipc_call_t call;
     727                ipc_callid_t callid = async_get_call(&call);
     728               
     729                /* Process the message */
     730                int res = tl_module_message_standalone(callid, &call, &answer,
     731                    &answer_count);
     732               
     733                /* End if said to either by the message or the processing result */
     734                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     735                        return;
     736               
     737                /* Answer the message */
     738                answer_call(callid, res, &answer, answer_count);
     739        }
     740}
     741
     742/** Starts the module.
     743 *
     744 *  @param argc The count of the command line arguments. Ignored parameter.
     745 *  @param argv The command line parameters. Ignored parameter.
     746 *
     747 *  @returns EOK on success.
     748 *  @returns Other error codes as defined for each specific module start function.
     749 *
     750 */
     751int main(int argc, char *argv[])
     752{
     753        ERROR_DECLARE;
     754       
     755        /* Start the module */
     756        if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
     757                return ERROR_CODE;
     758       
     759        return EOK;
     760}
     761
    700762/** @}
    701763 */
Note: See TracChangeset for help on using the changeset viewer.