public override bool ProcessPDU(LLCP_Link link, LLCP_PDU recv_pdu) { /* Server action */ /* ------------- */ link.RemotePort = recv_pdu.SSAP; link.LocalPort = (byte)(_server_port & 0x3F); switch (recv_pdu.PTYPE) { case LLCP_PDU.PTYPE_CONNECT: Trace.WriteLine("> CONNECT"); /* The client wants to connect us */ link.State = LLCP_Link.StateActive; if (!OnConnect(link, recv_pdu.Payload)) { /* Failed */ link.Send_DM(LLCP_DM_PDU.REASON_REJECTED); /* 03 */ /* Drop the link */ return(false); } else if (!link.Answered) { /* Confirm we agree (CC) */ link.Send_CC(); } break; case LLCP_PDU.PTYPE_DISC: Trace.WriteLine("> DISC"); /* The client is leaving us */ if (link.State == LLCP_Link.StateActive) { OnDisconnect(link); link.Send_DM(LLCP_DM_PDU.REASON_DISC_OK); /* 00 */ } else { link.Send_DM(LLCP_DM_PDU.REASON_NO_CONNECTION); /* 01 */ } /* Drop the link */ return(false); case LLCP_PDU.PTYPE_I: Trace.WriteLine("> I"); /* The client is talking to us */ if (link.State == LLCP_Link.StateActive) { byte nr = (byte)(recv_pdu.Sequence & 0x0F); byte ns = (byte)((recv_pdu.Sequence >> 4) & 0x0F); link.SetRemoteSequence((byte)((ns + 1) & 0x0F)); OnInformation(link, recv_pdu.Payload); if (!link.Answered) { /* No frame -> ACK */ link.Send_RR(); } } else { link.Send_DM(LLCP_DM_PDU.REASON_NO_CONNECTION); /* 01 */ } break; case LLCP_PDU.PTYPE_RR: Trace.WriteLine("> RR"); /* The client is acknowledging */ if (link.State == LLCP_Link.StateActive) { byte nr = (byte)(recv_pdu.Sequence & 0x0F); OnAcknowledge(link); } else { link.Send_DM(LLCP_DM_PDU.REASON_NO_CONNECTION); /* 01 */ } break; default: Trace.WriteLine("Unsupported LLCP frame client->server"); link.Send_FRMR(0x80, recv_pdu.PTYPE, 0x00); /* Drop the link */ return(false); } /* Keep the link OK */ return(true); }
public override bool ProcessPDU(LLCP_Link link, LLCP_PDU recv_pdu) { switch (recv_pdu.PTYPE) { case LLCP_PDU.PTYPE_CC: Trace.WriteLine("> CC"); if (link.State == LLCP_Link.StateOpening) { /* Connection accepted */ link.State = LLCP_Link.StateActive; OnConnect(link, recv_pdu.Payload); } break; case LLCP_PDU.PTYPE_DM: Trace.WriteLine("> DM"); /* Disconnect OK */ if (link.State == LLCP_Link.StateActive) { /* Peer is disconnecting */ link.State = LLCP_Link.StateClosed; OnDisconnect(link); } else { /* We were disconnecting - no need to invoke the callback */ link.State = LLCP_Link.StateClosed; } /* Drop the link */ return(false); case LLCP_PDU.PTYPE_I: Trace.WriteLine("> I"); /* The server is talking to us */ if (link.State == LLCP_Link.StateActive) { byte nr = (byte)(recv_pdu.Sequence & 0x0F); byte ns = (byte)((recv_pdu.Sequence >> 4) & 0x0F); OnInformation(link, recv_pdu.Payload); } break; case LLCP_PDU.PTYPE_RR: Trace.WriteLine("> RR"); /* Acknowledge */ if (link.State == LLCP_Link.StateActive) { byte nr = (byte)(recv_pdu.Sequence & 0x0F); OnAcknowledge(link); } break; case LLCP_PDU.PTYPE_RNR: Trace.WriteLine("> RNR"); break; default: Trace.WriteLine("Unsupported LLCP frame server->client"); link.Send_FRMR(0x80, recv_pdu.PTYPE, 0x00); /* Drop the link */ return(false); } /* Keep the link ON */ return(true); }