Exemplo n.º 1
0
 public NetIfDevice(Object owner, LinkDevice dev)
 {
     Owner        = owner;
     IoLinkDevice = dev;
     ReadQueue    = new BlockingCollection <byte[]>();
     dev.AddListener(owner, this.ComponentLinkListener);
 }
Exemplo n.º 2
0
 public LinkDriver GetLinkDriver(LinkDevice d)
 {
     foreach (LinkDriver p in IoNetIfs.Values)
     {
         if (p.Compare(d))
         {
             return(p);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        public bool AddDirectNetIf(LinkDevice dev, byte netIfIndex)
        {
            // Important: check device not already in use.
            if ((dev == null) || (Manager.GetLinkDriver(dev) != null))
            {
                return(false);
            }
            LinkDriver lp = new LinkDriver(Manager, dev, netIfIndex, true, true, true, false);

            Manager.AddDriver(lp);
            lp.StartLinkDriver();
            return(true);
        }
Exemplo n.º 4
0
        public bool AddListenerNetIf(LinkDevice dev, byte netIfIndex)
        {
            // Important: check device not already in use.
            if ((dev == null) || (Manager.GetLinkDriver(dev) != null))
            {
                return(false);
            }
            NetIfDevice pd = new NetIfDevice(this, dev); // TODO: who should owner be?
            LinkDriver  lp = new LinkDriver(Manager, pd, netIfIndex, true, true, true, false);

            Manager.AddDriver(lp);
            lp.StartLinkDriver();
            return(true);
        }
Exemplo n.º 5
0
 // Scan the current usb devices to check all connected.
 private void CheckConnections()
 {
     lock (UsbConnectionLock) {
         KLST_DEVINFO_HANDLE deviceInfo;
         LstK lst         = new LstK(KLST_FLAG.NONE);
         int  deviceCount = 0;
         lst.Count(ref deviceCount);
         while (lst.MoveNext(out deviceInfo))
         {
             LinkDevice d = LinkManager.Manager.FindDevice(UsbLinkDevice.GetDevIdFromHandle(deviceInfo));
             // Check if d is a suspended Acc with same SN but different V/P.
             if (d == null || ((d.State != ComponentState.Working) /*&& !UsbLinkDevice.CompareVidPid(d, deviceInfo)*/))
             {
                 if (UsbPermissionValidator.CheckAllowed(deviceInfo.Common.Vid, deviceInfo.Common.Pid))
                 {
                     UsbLinkDevice.TryOpeningDevice(deviceInfo);
                 }
             }
         }
         lst.Free();
     }
 }
Exemplo n.º 6
0
        // Check that LinkDevice and DEVINFO refer to same device by comparing Vid & Pid.
        // Returns truee if they do.
        public static bool CompareVidPid(LinkDevice d, KLST_DEVINFO_HANDLE h)
        {
            UsbLinkDevice u = d as UsbLinkDevice;

            return(u != null && u.DevPid == h.Common.Pid && u.DevVid == h.Common.Vid);
        }
Exemplo n.º 7
0
        // As well as opening the device:
        // Try putting it into accessory mode as necessary.
        // Returns null if unable to open or it was switched into accessory mode.
        // The steps for determining whether to connect to a usb device are:
        // 1) Consult vid/pid include & exclude lists.
        // 2) Open device.
        public static void TryOpeningDevice(KLST_DEVINFO_HANDLE deviceInfo)
        {
            bool          isNewDev, checkForAccessory;
            string        devId = GetDevIdFromHandle(deviceInfo);
            LinkDevice    d     = LinkManager.Manager.FindDevice(devId);
            UsbLinkDevice u     = d as UsbLinkDevice;

            if (u != null)
            {
                if (u.State == ComponentState.Working || u.State == ComponentState.Unresponsive)
                {
                    if (Settings.DebugLevel > 4)
                    {
                        Log.d(TAG, "TryOpeningDevice: already open:" + DeviceInfoToString(deviceInfo));
                    }
                    return;
                }
                // Check if d is a suspended Acc with same SN but different V/P.
                checkForAccessory = true; // !CompareVidPid(d, deviceInfo);
                u.CloseDevice();          //FIX: should already be closed?
                u.InitDevice(deviceInfo);
                isNewDev = false;
            }
            else
            {
                checkForAccessory = true;
                u        = new UsbLinkDevice(deviceInfo);
                isNewDev = true;
            }
            string result = null;

            lock (u.UsbLock) {
                result = u.ConfigureDevice(deviceInfo, checkForAccessory);
            }
            if (result == null)
            {
                u.SetSessionId();
                if (isNewDev)
                {
                    LinkManager.Manager.AddDevice(u.Id, u);
                    u.InitThreads();
                    u.NotifyStateChange(ComponentState.Working);
                }
                else
                {
                    u.Resume();
                }
            }
            else
            {
                u.DriverClose();
                if (Settings.DebugLevel > 4)
                {
                    Log.d(TAG, "ConfigureDevice: " + result);
                }
                if (!isNewDev)
                {
                    u.NotifyStateChange(ComponentState.Problem);
                }
                else             // Gets here if device was switched to acc mode.
                {
                    u.Id = null; // Prevents LinkManager.DeleteDevice being called on Close.
                }
            }
        }
Exemplo n.º 8
0
 public bool Compare(LinkDevice d)
 {
     return(IoLinkDevice == d);
 }
Exemplo n.º 9
0
 public bool Compare(LinkDevice d)
 {
     return(false);
 }
Exemplo n.º 10
0
 public bool Compare(LinkDevice d)
 {
     return(IoNetIfDevice.Compare(d));
 }