// Push message on to RNetIfIndex's Write Q. // Messages that cannot be posted are freed. public static void PostMessage(NetIfManager manager, int ioIndex, byte rNetIfIndex) { String dbgmsg = null; if (ioIndex == -1) { return; } LinkDriver p = manager.GetLinkDriver(rNetIfIndex); if (p == null) { rNetIfIndex = ProtocolConstants.NETIF_UNSET; } if ((p != null) || !isMaster) // Check destination netIf was not detached. { if (p == null) { p = manager.GetLinkDriver(ProtocolConstants.NETIF_BRIDGE_LINK); } if (p != null) { PacketBuffer b = manager.IoBuffers[ioIndex]; // Check for circular routing: examine prior destination netIf. if ((b.dNetIf != ProtocolConstants.NETIF_UNSET) && (b.dNetIf == rNetIfIndex)) { // Ignore circular messages. dbgmsg = String.Format("Circular message on netIf [{0}]: ditching message.", rNetIfIndex); } else { b.dNetIf = rNetIfIndex; if (p.NetIfIndex == ProtocolConstants.NETIF_BRIDGE_LINK) { byte netIfs = (byte)((rNetIfIndex << 4) | b.iNetIf); // Use destination to pass netIfs across bridge. b.destination((ushort)(((256 - netIfs) << 8) | netIfs)); } if (p.LinkWriteQueue.Push(ioIndex) != -1) // Check post queue not full. { if (Settings.DebugLevel > 6) { Log.d(TAG, "Posting:" + ioIndex + " to " + p.NetIfIndex); } return; } dbgmsg = String.Format("Write Q full on netIf [{0}]: ditching message.", rNetIfIndex); } } } // Messages that were not posted are freed. if (Settings.DebugLevel > 1) { Log.w(TAG, dbgmsg); } manager.IoBuffersFreeHeap.Release(ioIndex); }
// IOPort set up serial number for device at other end of link. // For the master port, set up temp SN and append netIfIndex. // For all other ports, set SN idx to null. It will be set when device connects. public void NetIfSerialNumberSetup(byte netIfIndex) { LinkDriver p = Manager.GetLinkDriver(netIfIndex); if (p != null) { if (netIfIndex == ProtocolConstants.NETIF_USER_BASE) { byte len; int idx = SerialNumbersFreeHeap.Allocate(); if (idx != -1) { len = Primitives.Strlen(MasterSN); CopyToSerialNumber(idx, len, MasterSN, 0); IoSerialNumbers[idx].Text[len - 1] = Primitives.NibbleToHexChar(netIfIndex); } p.SerialIndex = idx; } else { p.SerialIndex = -1; } } }