Ignore:
File:
1 edited

Legend:

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

    r14f1db0 r6092b56e  
    4040#include <malloc.h>
    4141#include <stdio.h>
     42
    4243#include <ipc/ipc.h>
    4344#include <ipc/services.h>
    4445
    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>
     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"
    6971
    7072#include "udp.h"
    7173#include "udp_header.h"
    7274#include "udp_module.h"
    73 
    74 /** UDP module name.
    75  */
    76 #define NAME    "UDP protocol"
    7775
    7876/** Default UDP checksum computing.
     
    261259        icmp_type_t type;
    262260        icmp_code_t code;
    263         void *ip_header;
     261        ip_pseudo_header_ref ip_header;
    264262        struct sockaddr * src;
    265263        struct sockaddr * dest;
     
    359357                        while(tmp_packet){
    360358                                next_packet = pq_detach(tmp_packet);
    361                                 pq_release_remote(udp_globals.net_phone, packet_get_id(tmp_packet));
     359                                pq_release(udp_globals.net_phone, packet_get_id(tmp_packet));
    362360                                tmp_packet = next_packet;
    363361                        }
     
    385383        // queue the received packet
    386384        if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE))
    387             || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){
     385                || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){
    388386                return udp_release_and_return(packet, ERROR_CODE);
    389387        }
     
    395393}
    396394
    397 int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     395int udp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    398396        ERROR_DECLARE;
    399397
     
    403401        switch(IPC_GET_METHOD(*call)){
    404402                case NET_TL_RECEIVED:
    405                         if(! ERROR_OCCURRED(packet_translate_remote(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     403                        if(! ERROR_OCCURRED(packet_translate(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    406404                                ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_UDP, IPC_GET_ERROR(call));
    407405                        }
     
    421419        int socket_id;
    422420        size_t addrlen;
    423         size_t size;
    424421        ipc_call_t answer;
    425422        int answer_count;
     
    457454                                socket_id = SOCKET_GET_SOCKET_ID(call);
    458455                                res = socket_create(&local_sockets, app_phone, NULL, &socket_id);
    459                                 SOCKET_SET_SOCKET_ID(answer, socket_id);
    460 
     456                                *SOCKET_SET_SOCKET_ID(answer) = socket_id;
     457                               
    461458                                if(res == EOK){
    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);
     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;
    464461                                        }
    465 //                                      SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_UDP_FRAGMENT_SIZE);
    466                                         SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
     462//                                      *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_UDP_FRAGMENT_SIZE;
     463                                        *SOCKET_SET_HEADER_SIZE(answer) = UDP_HEADER_SIZE;
    467464                                        answer_count = 3;
    468465                                }
     
    481478                                if(res == EOK){
    482479                                        fibril_rwlock_write_lock(&udp_globals.lock);
    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);
     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));
    485481                                        if(res != EOK){
    486482                                                fibril_rwlock_write_unlock(&udp_globals.lock);
     
    496492                                fibril_rwlock_write_unlock(&udp_globals.lock);
    497493                                if(res > 0){
    498                                         SOCKET_SET_READ_DATA_LENGTH(answer, res);
    499                                         SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
     494                                        *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
     495                                        *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
    500496                                        answer_count = 3;
    501497                                        res = EOK;
     
    536532        uint16_t dest_port;
    537533        uint32_t checksum;
    538         void *ip_header;
     534        ip_pseudo_header_ref ip_header;
    539535        size_t headerlen;
    540536        device_id_t device_id;
     
    665661                return NO_DATA;
    666662        }
    667         ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, packet_id));
     663        ERROR_PROPAGATE(packet_translate(udp_globals.net_phone, &packet, packet_id));
    668664        // get udp header
    669665        data = packet_get_data(packet);
    670666        if(! data){
    671                 pq_release_remote(udp_globals.net_phone, packet_id);
     667                pq_release(udp_globals.net_phone, packet_id);
    672668                return NO_DATA;
    673669        }
     
    677673        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    678674        if(ERROR_OCCURRED(tl_set_address_port(addr, result, ntohs(header->source_port)))){
    679                 pq_release_remote(udp_globals.net_phone, packet_id);
     675                pq_release(udp_globals.net_phone, packet_id);
    680676                return ERROR_CODE;
    681677        }
     
    692688        // release the packet
    693689        dyn_fifo_pop(&socket->received);
    694         pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
     690        pq_release(udp_globals.net_phone, packet_get_id(packet));
    695691        // return the total length
    696692        return (int) length;
     
    698694
    699695int udp_release_and_return(packet_t packet, int result){
    700         pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
     696        pq_release(udp_globals.net_phone, packet_get_id(packet));
    701697        return result;
    702698}
    703699
    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  */
    710 static 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  */
    751 int 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 
    762700/** @}
    763701 */
Note: See TracChangeset for help on using the changeset viewer.