Changeset 64d138b in mainline


Ignore:
Timestamp:
2017-12-15T17:21:49Z (6 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
73b0773
Parents:
a8723748
Message:

usbdiag: finalize IPC ops for tmon, simple demo waiting for test

Location:
uspace
Files:
1 added
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/Makefile

    ra8723748 r64d138b  
    3030BINARY = tmon
    3131
    32 LIBS = usbdiag
     32LIBS = drv usbdiag
    3333
    3434SOURCES = \
  • uspace/app/tmon/main.c

    ra8723748 r64d138b  
    3636
    3737#include <stdio.h>
     38#include <loc.h>
    3839#include <usb/diag/diag.h>
     40#include <usb/diag/iface.h>
     41#include <devman.h>
     42#include <errno.h>
    3943
    4044#define NAME "tmon"
     
    4347{
    4448        printf(NAME ": hello USB transfers!\n\n");
     49}
     50
     51static void print_list_item(service_id_t svc)
     52{
     53        int rc;
     54        devman_handle_t diag_handle = 0;
     55
     56        if ((rc = devman_fun_sid_to_handle(svc, &diag_handle))) {
     57                printf(NAME ": Error resolving handle of device with SID %ld, skipping.\n", svc);
     58                return;
     59        }
     60}
     61
     62static int print_list()
     63{
     64        category_id_t diag_cat;
     65        service_id_t *svcs;
     66        size_t count;
     67        int rc;
     68
     69        if ((rc = loc_category_get_id(USB_DIAG_CATEGORY, &diag_cat, 0))) {
     70                printf(NAME ": Error resolving category '%s'", USB_DIAG_CATEGORY);
     71                return 1;
     72        }
     73
     74        if ((rc = loc_category_get_svcs(diag_cat, &svcs, &count))) {
     75                printf(NAME ": Error getting list of host controllers.\n");
     76                return 1;
     77        }
     78
     79        for (unsigned i = 0; i < count; ++i) {
     80                print_list_item(svcs[i]);
     81        }
     82
     83        free(svcs);
     84        return 0;
    4585}
    4686
     
    5292        }
    5393
    54         int out;
    55         const int rc = usb_diag_test(0, &out);
    56         if (rc) {
    57                 printf("Error: %d\n", rc);
    58         } else {
    59                 printf("The number is %d.\n", out);
    60         }
    61 
    62         return 0;
     94        return print_list();
    6395}
    6496
  • uspace/drv/bus/usb/usbdiag/device.c

    ra8723748 r64d138b  
    3636#include <errno.h>
    3737#include <usb/debug.h>
     38#include <usb/diag/iface.h>
    3839
    3940#include "device.h"
     
    4142#define NAME "usbdiag"
    4243
     44static void connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     45{
     46        // usb_diag_fun_t *fun = (usb_diag_fun_t *) ddf_fun_data_get((ddf_fun_t *) arg);
     47
     48        // FIXME: handle connection
     49}
     50
     51static int some_test(ddf_fun_t *fun, int x, int *y)
     52{
     53        *y = x + 42;
     54        return EOK;
     55}
     56
     57static usb_diag_iface_t diag_interface = {
     58        .test = some_test,
     59};
     60
     61static ddf_dev_ops_t diag_ops = {
     62        .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
     63};
     64
    4365static int device_init(usb_diag_dev_t *dev)
    4466{
    45         // TODO: allocate data structures, set up stuffs
     67        ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
     68        if (!fun)
     69                return ENOMEM;
    4670
     71        ddf_fun_set_conn_handler(fun, connection);
     72        ddf_fun_set_ops(fun, &diag_ops);
     73
     74        dev->fun = fun;
    4775        return EOK;
    4876}
     
    5078static void device_fini(usb_diag_dev_t *dev)
    5179{
    52         // TODO: tear down data structures
     80        ddf_fun_destroy(dev->fun);
    5381}
    5482
  • uspace/drv/bus/usb/usbdiag/device.h

    ra8723748 r64d138b  
    4040
    4141/**
    42  * USB debug device.
     42 * USB diagnostic device.
    4343 */
    4444typedef struct usb_diag_dev {
    4545        usb_device_t *usb_dev;
     46        ddf_fun_t *fun;
    4647} usb_diag_dev_t;
    4748
  • uspace/drv/bus/usb/usbdiag/main.c

    ra8723748 r64d138b  
    3838#include <usb/dev/driver.h>
    3939#include <usb/diag/diag.h>
     40#include <str_error.h>
    4041
    4142#include "usbdiag.h"
     
    4445#define NAME "usbdiag"
    4546
    46 static void usb_diag_test_impl(ipc_callid_t rid, ipc_call_t *request)
    47 {
    48         int x = IPC_GET_ARG1(*request);
    49         int ret = 4200 + x;
    50         async_answer_0(rid, ret);
    51 }
    52 
    5347static int device_add(usb_device_t *dev)
    5448{
     49        int rc;
    5550        usb_log_info("Adding device '%s'", usb_device_get_name(dev));
    5651
    57         int err;
     52        usb_diag_dev_t *diag_dev;
     53        if ((rc = usb_diag_dev_create(dev, &diag_dev))) {
     54                usb_log_error("Failed create device: %s.\n", str_error(rc));
     55                goto err;
     56        }
    5857
    59         usb_diag_dev_t *diag_dev;
    60         if ((err = usb_diag_dev_create(dev, &diag_dev)))
    61                 return err;
     58        if ((rc = ddf_fun_bind(diag_dev->fun))) {
     59                usb_log_error("Failed to bind DDF function: %s.\n", str_error(rc));
     60                goto err_create;
     61        }
    6262
    63         /* TODO: Register device in some list. */
    64         /* TODO: Register device DDF function. */
     63        if ((rc = ddf_fun_add_to_category(diag_dev->fun, USB_DIAG_CATEGORY))) {
     64                usb_log_error("Failed add DDF to category '"
     65                    USB_DIAG_CATEGORY "': %s.\n", str_error(rc));
     66                goto err_bind;
     67        }
    6568
    6669        return EOK;
     70
     71err_bind:
     72        ddf_fun_unbind(diag_dev->fun);
     73err_create:
     74        usb_diag_dev_destroy(diag_dev);
     75err:
     76        return rc;
    6777}
    6878
    6979static int device_remove(usb_device_t *dev)
    7080{
     81        int rc;
    7182        usb_log_info("Removing device '%s'", usb_device_get_name(dev));
    7283
     
    7485
    7586        /* TODO: Make sure nothing is going on with the device. */
    76         /* TODO: Unregister device DDF function. */
    77         /* TODO: Remove device from list */
     87
     88        if ((rc = ddf_fun_unbind(diag_dev->fun))) {
     89                usb_log_error("Failed to unbind DDF function: %s\n", str_error(rc));
     90                goto err;
     91        }
    7892
    7993        usb_diag_dev_destroy(diag_dev);
    8094
    8195        return EOK;
     96
     97err:
     98        return rc;
    8299}
    83100
     
    107124}
    108125
    109 static void connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    110 {
    111         bool cont = true;
    112 
    113         async_answer_0(iid, EOK);
    114 
    115         while (cont) {
    116                 ipc_call_t call;
    117                 ipc_callid_t callid = async_get_call(&call);
    118 
    119                 if (!IPC_GET_IMETHOD(call))
    120                         break;
    121 
    122                 switch (IPC_GET_IMETHOD(call)) {
    123                 case USB_DIAG_IN_TEST:
    124                         usb_diag_test_impl(callid, &call);
    125                         break;
    126                 default:
    127                         async_answer_0(callid, ENOTSUP);
    128                         break;
    129                 }
    130         }
    131 }
    132 
    133 static int server_fibril(void *arg)
    134 {
    135         // async_set_client_data_constructor(NULL);
    136         // async_set_client_data_destructor(NULL);
    137         async_set_fallback_port_handler(connection, NULL);
    138         // async_event_task_subscribe();
    139         // service_register();
    140         async_manager();
    141 
    142         /* Never reached. */
    143         return EOK;
    144 }
    145 
    146126/** USB diagnostic driver ops. */
    147127static const usb_driver_ops_t diag_driver_ops = {
     
    166146        log_init(NAME);
    167147
    168         /* Start usbdiag service. */
    169         fid_t srv = fibril_create(server_fibril, NULL);
    170         if (!srv)
    171                 return ENOMEM;
    172         fibril_add_ready(srv);
    173 
    174148        return usb_driver_main(&diag_driver);
    175149}
  • uspace/lib/c/include/ipc/dev_iface.h

    ra8723748 r64d138b  
    4444        /** Audio device pcm buffer interface */
    4545        AUDIO_PCM_BUFFER_IFACE,
    46        
     46
    4747        /** Network interface controller interface */
    4848        NIC_DEV_IFACE,
    49                
     49
    5050        /** IEEE 802.11 interface controller interface */
    5151        IEEE80211_DEV_IFACE,
    52        
     52
    5353        /** Interface provided by any PCI device. */
    5454        PCI_DEV_IFACE,
     
    5656        /** Interface provided by any USB device. */
    5757        USB_DEV_IFACE,
     58        /** Interface provided by USB diagnostic devices. */
     59        USBDIAG_DEV_IFACE,
    5860        /** Interface provided by USB host controller to USB device. */
    5961        USBHC_DEV_IFACE,
  • uspace/lib/usbdiag/Makefile

    ra8723748 r64d138b  
    3232
    3333SOURCES = \
    34         src/test.c
     34        src/remote_usbdiag.c
    3535
    3636include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usbdiag/include/usb/diag/diag.h

    ra8723748 r64d138b  
    3636#define LIBUSBDIAG_DIAG_H_
    3737
    38 #include <ipc/common.h>
    39 
    40 typedef enum {
    41   USB_DIAG_IN_TEST = IPC_FIRST_USER_METHOD,
    42 } usb_diag_in_request_t;
    43 
    44 /** Just a dummy symbol to make compiler happy. TODO: remove it */
    45 int usb_diag_test(int, int*);
     38#define USB_DIAG_CATEGORY "usbdiag"
    4639
    4740#endif
  • uspace/lib/usbdiag/include/usb/diag/iface.h

    ra8723748 r64d138b  
    3131 */
    3232/** @file
    33  * Testing stuff
     33 * @brief USB diagnostic device communication interface.
    3434 */
     35#ifndef LIBUSBDIAG_IFACE_H_
     36#define LIBUSBDIAG_IFACE_H_
    3537
    3638#include <async.h>
    37 #include <usb/diag/diag.h>
     39#include <ddf/driver.h>
    3840
    39 int usb_diag_test(int x, int *out)
    40 {
    41         sysarg_t _out;
    42         async_sess_t *session = NULL;
    43         async_exch_t *exch = async_exchange_begin(session);
    44         const int rc = async_req_1_1(exch, USB_DIAG_IN_TEST, x, &_out);
    45         async_exchange_end(exch);
     41async_sess_t *usb_diag_connect(devman_handle_t);
     42void usb_diag_disconnect(async_sess_t*);
     43int usb_diag_test(async_exch_t*, int, int*);
    4644
    47         if (out)
    48                 *out = (int) _out;
     45/** USB diagnostic device communication interface. */
     46typedef struct {
     47        int (*test)(ddf_fun_t*, int, int*);
     48} usb_diag_iface_t;
    4949
    50         return rc;
    51 }
    52 
     50#endif
    5351/**
    5452 * @}
  • uspace/srv/locsrv/locsrv.c

    ra8723748 r64d138b  
    13531353        categ_dir_add_cat(&cdir, cat);
    13541354
     1355        cat = category_new("usbdiag");
     1356        categ_dir_add_cat(&cdir, cat);
     1357
    13551358        cat = category_new("usbhc");
    13561359        categ_dir_add_cat(&cdir, cat);
Note: See TracChangeset for help on using the changeset viewer.