Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/arp/arp.c

    r19f857a r14f1db0  
    4343#include <str.h>
    4444#include <task.h>
    45 
    4645#include <ipc/ipc.h>
    4746#include <ipc/services.h>
    4847
    49 #include "../../err.h"
    50 #include "../../messages.h"
    51 #include "../../modules.h"
    52 
    53 #include "../../include/byteorder.h"
    54 #include "../../include/device.h"
    55 #include "../../include/arp_interface.h"
    56 #include "../../include/nil_interface.h"
    57 #include "../../include/protocol_map.h"
    58 
    59 #include "../../structures/measured_strings.h"
    60 #include "../../structures/packet/packet.h"
    61 #include "../../structures/packet/packet_client.h"
    62 
    63 #include "../il_messages.h"
     48#include <net_err.h>
     49#include <net_messages.h>
     50#include <net_modules.h>
     51#include <net_byteorder.h>
     52#include <net_device.h>
     53#include <arp_interface.h>
     54#include <nil_interface.h>
     55#include <protocol_map.h>
     56#include <adt/measured_strings.h>
     57#include <packet/packet.h>
     58#include <packet/packet_client.h>
     59#include <packet_remote.h>
     60#include <il_messages.h>
     61#include <il_interface.h>
     62#include <il_local.h>
     63#include <arp_messages.h>
    6464
    6565#include "arp.h"
     
    6767#include "arp_oc.h"
    6868#include "arp_module.h"
    69 #include "arp_messages.h"
     69
     70
     71/** ARP module name.
     72 */
     73#define NAME  "arp"
    7074
    7175/** ARP global data.
     
    337341                        return ERROR_CODE;
    338342                }
    339                 printf("New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n\tproto\t= %d\n", device->device_id, device->hardware, device->service, protocol);
     343                printf("%s: Device registered (id: %d, type: 0x%x, service: %d, proto: %d)\n",
     344                    NAME, device->device_id, device->hardware, device->service, protocol);
    340345        }
    341346        fibril_rwlock_write_unlock(&arp_globals.lock);
     
    368373}
    369374
    370 int arp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     375int arp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     376    ipc_call_t *answer, int *answer_count)
     377{
    371378        ERROR_DECLARE;
    372 
     379       
    373380        measured_string_ref address;
    374381        measured_string_ref translation;
     
    376383        packet_t packet;
    377384        packet_t next;
    378 
    379 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_ARP_FIRST);
     385       
    380386        *answer_count = 0;
    381         switch(IPC_GET_METHOD(*call)){
     387        switch (IPC_GET_METHOD(*call)) {
    382388                case IPC_M_PHONE_HUNGUP:
    383389                        return EOK;
     
    416422                        return EOK;
    417423                case NET_IL_RECEIVED:
    418                         if(! ERROR_OCCURRED(packet_translate(arp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     424                        if(! ERROR_OCCURRED(packet_translate_remote(arp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    419425                                fibril_rwlock_read_lock(&arp_globals.lock);
    420426                                do{
     
    422428                                        ERROR_CODE = arp_receive_message(IPC_GET_DEVICE(call), packet);
    423429                                        if(ERROR_CODE != 1){
    424                                                 pq_release(arp_globals.net_phone, packet_get_id(packet));
     430                                                pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    425431                                        }
    426432                                        packet = next;
     
    432438                        return arp_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call));
    433439        }
     440       
    434441        return ENOTSUP;
    435442}
     
    568575                return NULL;
    569576        }
    570         packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
     577        packet = packet_get_4_remote(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
    571578        if(! packet){
    572579                return NULL;
     
    574581        header = (arp_header_ref) packet_suffix(packet, length);
    575582        if(! header){
    576                 pq_release(arp_globals.net_phone, packet_get_id(packet));
     583                pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    577584                return NULL;
    578585        }
     
    591598        memcpy(((uint8_t *) header) + length, target->value, target->length);
    592599        if(packet_set_addr(packet, (uint8_t *) device->addr->value, (uint8_t *) device->broadcast_addr->value, CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK){
    593                 pq_release(arp_globals.net_phone, packet_get_id(packet));
     600                pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    594601                return NULL;
    595602        }
     
    618625}
    619626
     627/** Default thread for new connections.
     628 *
     629 *  @param[in] iid The initial message identifier.
     630 *  @param[in] icall The initial message call structure.
     631 *
     632 */
     633static void il_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     634{
     635        /*
     636         * Accept the connection
     637         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     638         */
     639        ipc_answer_0(iid, EOK);
     640       
     641        while(true) {
     642                ipc_call_t answer;
     643                int answer_count;
     644               
     645                /* Clear the answer structure */
     646                refresh_answer(&answer, &answer_count);
     647               
     648                /* Fetch the next message */
     649                ipc_call_t call;
     650                ipc_callid_t callid = async_get_call(&call);
     651               
     652                /* Process the message */
     653                int res = il_module_message_standalone(callid, &call, &answer,
     654                    &answer_count);
     655               
     656                /* End if said to either by the message or the processing result */
     657                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     658                        return;
     659               
     660                /* Answer the message */
     661                answer_call(callid, res, &answer, answer_count);
     662        }
     663}
     664
     665/** Starts the module.
     666 *
     667 *  @param argc The count of the command line arguments. Ignored parameter.
     668 *  @param argv The command line parameters. Ignored parameter.
     669 *
     670 *  @returns EOK on success.
     671 *  @returns Other error codes as defined for each specific module start function.
     672 *
     673 */
     674int main(int argc, char *argv[])
     675{
     676        ERROR_DECLARE;
     677       
     678        /* Start the module */
     679        if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection)))
     680                return ERROR_CODE;
     681       
     682        return EOK;
     683}
     684
    620685/** @}
    621686 */
Note: See TracChangeset for help on using the changeset viewer.