Ejemplo n.º 1
0
        public static void LinkActionCallback(Object stateInfo)
        {
            Message          m             = (Message)stateInfo;
            ConnectionHelper ch            = Program.toMihf;
            ushort           transactionID = m.MIHHeader.TransactionID;

            Payload.TLVIterator it = m.Payload.GetTLVIterator();
            ID srcID = new ID(new OctetString(it.Next().Value));
            ID dstID = new ID(new OctetString(it.Next().Value));
            Link_Action_Request lar = new Link_Action_Request(MIHDeserializer.DeserializeLinkAction(it.Next()),
                                                              MIHDeserializer.DeserializeTimeInterval(it.Next()),
                                                              MIHDeserializer.DeserializePoA(it.Next()));

            Link_Action_Response laresp = new Link_Action_Response();

            laresp.Status = STATUS.UNSPECIFIED_FAILURE;
            laresp.Result = Link_Ac_Result.INCAPABLE;

            NativeWifi.WlanClient.WlanInterface iface = null;
            try { iface = Information.GenericInfo.WlanInterfaceInstance; }
            catch (Exception e) { /*nothing*/ }
            switch (lar.LinkAction.LinkAcType)
            {
            case Link_Ac_Type.LINK_DISCONNECT:
                ActionsInterface.Action_Disconnect(ref laresp, ref iface);
                break;

            case Link_Ac_Type.NONE:
                Console.WriteLine("No action performed.");
                laresp.Status = STATUS.SUCCESS;
                laresp.Result = Link_Ac_Result.SUCCESS;
                break;

            case Link_Ac_Type.LINK_POWER_DOWN:
                ActionsInterface.Action_Power_Down(ref laresp, ref iface);
                break;

            case Link_Ac_Type.LINK_POWER_UP:
                ActionsInterface.Action_Power_Up(ref laresp, ref iface);
                break;

            default:
                throw new InvalidOperationException("Unsupported Operation");
            }
            laresp.ScanResults = new List <Link_Scan_Rsp>();
            if (lar.LinkAction.LinkAcAttr.Link_Scan)
            {
                ActionsInterface.Action_Scan(laresp, iface, m);//Message is sent inside this  branch, after the scan is complete.
            }
            else
            {
                ch.Send(ResponseBuilders.Link_Action_Response_Builder(srcID, dstID, transactionID, laresp).ByteValue);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prints a serialized message.
        /// </summary>
        /// <param name="m">The serialized message to print.</param>
        public static void PrintMessage(Message m)
        {
            Payload.TLVIterator it = m.Payload.GetTLVIterator();
            Console.Write("\t(");
            Console.Write(new ID(new OctetString(it.Next().Value)));
            Console.Write(" -> " + new ID(new OctetString(it.Next().Value)));
            Console.Write(")");
            Console.WriteLine();
            switch (m.MIHHeader.MID.AID)
            {
            case AIDGlobal.COMMAND_SERVICE_MIH_LINK_ACTIONS:
                if (m.MIHHeader.MID.OpCode == MessageID.OperationCode.REQUEST)
                {
                    //LINK ACTION REQUEST
                    Console.WriteLine(new Link_Action_Request(MIHDeserializer.DeserializeLinkAction(it.Next()),
                                                              MIHDeserializer.DeserializeTimeInterval(it.Next()),
                                                              MIHDeserializer.DeserializePoA(it.Next())).ToString());
                }
                else
                {
                    //LINK ACTION RESPONSE
                    if (it.Count == 5)
                    {
                        Console.WriteLine(new Link_Action_Response(MIHDeserializer.DeserializeStatus(it.Next()),
                                                                   MIHDeserializer.DeserializeLinkScanRspList(it.Next()),
                                                                   MIHDeserializer.DeserializeLinkAcResult(it.Next())));
                    }
                    else
                    {
                        Console.WriteLine(new Link_Action_Response(MIHDeserializer.DeserializeStatus(it.Next()),
                                                                   new List <byte[]>(),
                                                                   MIHDeserializer.DeserializeLinkAcResult(it.Next())));
                    }
                }
                break;

            case AIDGlobal.EVENT_SERVICE_MIH_LINK_UP:
                Console.WriteLine(new Link_Up(MIHDeserializer.DeserializeLinkTupleId(it.Next()), null, null));
                break;

            case AIDGlobal.EVENT_SERVICE_MIH_LINK_DOWN:
                Console.WriteLine(
                    it.Count < 5?
                    new Link_Down(MIHDeserializer.DeserializeLinkTupleId(it.Next()),
                                  null,
                                  MIHDeserializer.DeserializeLinkDnReason(it.Next()))
                            :
                    new Link_Down(MIHDeserializer.DeserializeLinkTupleId(it.Next()),
                                  MIHDeserializer.DeserializeOldAccessRouter(it.Next()),
                                  MIHDeserializer.DeserializeLinkDnReason(it.Next()))
                    );
                break;

            case AIDGlobal.EVENT_SERVICE_MIH_LINK_DETECTED:
                Console.WriteLine(new Link_Detected(MIHDeserializer.DeserializeLinkDetInfo(it.Next())));
                break;

            case AIDGlobal.COMMAND_SERVICE_MIH_LINK_GET_PARAMETERS:
                if (m.MIHHeader.MID.OpCode == MessageID.OperationCode.REQUEST)
                {
                    Console.WriteLine(new Link_Get_Parameters_Request(MIHDeserializer.DeserializeLinkParamRequest(it.Next()),
                                                                      it.Next().Value, it.Next().Value));
                }
                else
                {
                    Console.WriteLine(new Link_Get_Parameters_Confirm(MIHDeserializer.DeserializeStatus(it.Next()),
                                                                      MIHDeserializer.DeserializeLinkParamStatusList(it.Next()),
                                                                      MIHDeserializer.DeserializeLinkStatesResponse(it.Next()),
                                                                      MIHDeserializer.DeserializeLinkDescriptorsResponse(it.Next())));
                }
                break;

            default: Console.WriteLine("N/A"); break;
            }
        }