Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/nil/eth/eth.c

    r19f857a r14f1db0  
    4545#include <ipc/services.h>
    4646
    47 #include "../../err.h"
    48 #include "../../messages.h"
    49 #include "../../modules.h"
    50 
    51 #include "../../include/byteorder.h"
    52 #include "../../include/checksum.h"
    53 #include "../../include/ethernet_lsap.h"
    54 #include "../../include/ethernet_protocols.h"
    55 #include "../../include/protocol_map.h"
    56 #include "../../include/device.h"
    57 #include "../../include/netif_interface.h"
    58 #include "../../include/net_interface.h"
    59 #include "../../include/nil_interface.h"
    60 #include "../../include/il_interface.h"
    61 
    62 #include "../../structures/measured_strings.h"
    63 #include "../../structures/packet/packet_client.h"
    64 
    65 #include "../nil_module.h"
     47#include <net_err.h>
     48#include <net_messages.h>
     49#include <net_modules.h>
     50#include <net_byteorder.h>
     51#include <net_checksum.h>
     52#include <ethernet_lsap.h>
     53#include <ethernet_protocols.h>
     54#include <protocol_map.h>
     55#include <net_device.h>
     56#include <netif_interface.h>
     57#include <net_interface.h>
     58#include <nil_interface.h>
     59#include <il_interface.h>
     60#include <adt/measured_strings.h>
     61#include <packet/packet_client.h>
     62#include <packet_remote.h>
     63#include <nil_local.h>
    6664
    6765#include "eth.h"
    6866#include "eth_header.h"
     67
     68/** The module name.
     69 */
     70#define NAME  "eth"
    6971
    7072/** Reserved packet prefix length.
     
    270272INT_MAP_IMPLEMENT(eth_protos, eth_proto_t)
    271273
    272 int nil_device_state_msg(int nil_phone, device_id_t device_id, int state){
     274int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state){
    273275        int index;
    274276        eth_proto_ref proto;
     
    401403                        return index;
    402404                }
    403                 printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n\tflags\t= 0x%x\n", device->device_id, device->service, device->mtu, device->addr_data[0], device->addr_data[1], device->addr_data[2], device->addr_data[3], device->addr_data[4], device->addr_data[5], device->flags);
     405                printf("%s: Device registered (id: %d, service: %d: mtu: %d, "
     406                    "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n",
     407                    NAME, device->device_id, device->service, device->mtu,
     408                    device->addr_data[0], device->addr_data[1],
     409                    device->addr_data[2], device->addr_data[3],
     410                    device->addr_data[4], device->addr_data[5], device->flags);
    404411        }
    405412        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    469476}
    470477
    471 int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
     478int nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
    472479        eth_proto_ref proto;
    473480        packet_t next;
     
    491498                }else{
    492499                        // drop invalid/unknown
    493                         pq_release(eth_globals.net_phone, packet_get_id(packet));
     500                        pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
    494501                }
    495502                packet = next;
     
    571578                }
    572579        }
    573         printf("New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone);
     580       
     581        printf("%s: Protocol registered (protocol: %d, service: %d, phone: %d)\n",
     582            NAME, proto->protocol, proto->service, proto->phone);
     583       
    574584        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    575585        return EOK;
     
    672682        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    673683        if(! ethertype){
    674                 pq_release(eth_globals.net_phone, packet_get_id(packet));
     684                pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
    675685                return EINVAL;
    676686        }
     
    690700                                packet = tmp;
    691701                        }
    692                         pq_release(eth_globals.net_phone, packet_get_id(next));
     702                        pq_release_remote(eth_globals.net_phone, packet_get_id(next));
    693703                        next = tmp;
    694704                }else{
     
    704714}
    705715
    706 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     716int nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
     717    ipc_call_t *answer, int *answer_count)
     718{
    707719        ERROR_DECLARE;
    708 
     720       
    709721        measured_string_ref address;
    710722        packet_t packet;
    711 
    712 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
     723        size_t addrlen;
     724        size_t prefix;
     725        size_t suffix;
     726        size_t content;
     727       
    713728        *answer_count = 0;
    714         switch(IPC_GET_METHOD(*call)){
     729        switch (IPC_GET_METHOD(*call)) {
    715730                case IPC_M_PHONE_HUNGUP:
    716731                        return EOK;
    717732                case NET_NIL_DEVICE:
    718                         return eth_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call));
     733                        return eth_device_message(IPC_GET_DEVICE(call),
     734                            IPC_GET_SERVICE(call), IPC_GET_MTU(call));
    719735                case NET_NIL_SEND:
    720                         ERROR_PROPAGATE(packet_translate(eth_globals.net_phone, &packet, IPC_GET_PACKET(call)));
    721                         return eth_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call));
     736                        ERROR_PROPAGATE(packet_translate_remote(eth_globals.net_phone, &packet,
     737                            IPC_GET_PACKET(call)));
     738                        return eth_send_message(IPC_GET_DEVICE(call), packet,
     739                            IPC_GET_SERVICE(call));
    722740                case NET_NIL_PACKET_SPACE:
    723                         ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), IPC_SET_ADDR(answer), IPC_SET_PREFIX(answer), IPC_SET_CONTENT(answer), IPC_SET_SUFFIX(answer)));
     741                        ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call),
     742                            &addrlen, &prefix, &content, &suffix));
     743                        IPC_SET_ADDR(answer, addrlen);
     744                        IPC_SET_PREFIX(answer, prefix);
     745                        IPC_SET_CONTENT(answer, content);
     746                        IPC_SET_SUFFIX(answer, suffix);
    724747                        *answer_count = 4;
    725748                        return EOK;
    726749                case NET_NIL_ADDR:
    727                         ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, &address));
     750                        ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call),
     751                            ETH_LOCAL_ADDR, &address));
    728752                        return measured_strings_reply(address, 1);
    729753                case NET_NIL_BROADCAST_ADDR:
    730                         ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, &address));
     754                        ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call),
     755                            ETH_BROADCAST_ADDR, &address));
    731756                        return measured_strings_reply(address, 1);
    732757                case IPC_M_CONNECT_TO_ME:
    733                         return eth_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call));
    734         }
     758                        return eth_register_message(NIL_GET_PROTO(call),
     759                            IPC_GET_PHONE(call));
     760        }
     761       
    735762        return ENOTSUP;
    736763}
     
    745772                switch(IPC_GET_METHOD(*icall)){
    746773                        case NET_NIL_DEVICE_STATE:
    747                                 nil_device_state_msg(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
     774                                nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
    748775                                ipc_answer_0(iid, EOK);
    749776                                break;
    750777                        case NET_NIL_RECEIVED:
    751                                 if(! ERROR_OCCURRED(packet_translate(eth_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){
    752                                         ERROR_CODE = nil_received_msg(0, IPC_GET_DEVICE(icall), packet, 0);
     778                                if(! ERROR_OCCURRED(packet_translate_remote(eth_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){
     779                                        ERROR_CODE = nil_received_msg_local(0, IPC_GET_DEVICE(icall), packet, 0);
    753780                                }
    754781                                ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
     
    761788}
    762789
     790#ifndef CONFIG_NETIF_NIL_BUNDLE
     791
     792/** Default thread for new connections.
     793 *
     794 * @param[in] iid The initial message identifier.
     795 * @param[in] icall The initial message call structure.
     796 *
     797 */
     798static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     799{
     800        /*
     801         * Accept the connection
     802         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     803         */
     804        ipc_answer_0(iid, EOK);
     805       
     806        while(true) {
     807                ipc_call_t answer;
     808                int answer_count;
     809               
     810                /* Clear the answer structure */
     811                refresh_answer(&answer, &answer_count);
     812               
     813                /* Fetch the next message */
     814                ipc_call_t call;
     815                ipc_callid_t callid = async_get_call(&call);
     816               
     817                /* Process the message */
     818                int res = nil_module_message_standalone(NAME, callid, &call, &answer,
     819                    &answer_count);
     820               
     821                /* End if said to either by the message or the processing result */
     822                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     823                        return;
     824               
     825                /* Answer the message */
     826                answer_call(callid, res, &answer, answer_count);
     827        }
     828}
     829
     830int main(int argc, char *argv[])
     831{
     832        ERROR_DECLARE;
     833       
     834        /* Start the module */
     835        if (ERROR_OCCURRED(nil_module_start_standalone(nil_client_connection)))
     836                return ERROR_CODE;
     837       
     838        return EOK;
     839}
     840
     841#endif /* CONFIG_NETIF_NIL_BUNDLE */
     842
    763843/** @}
    764844 */
Note: See TracChangeset for help on using the changeset viewer.