Exemplo n.º 1
0
 private bool SendReply(Stream s)
 {
     EIBHeader header = new EIBHeader(s);
     s.Position = 0;
     bool res = false;
     switch (header.mc)
     {
         case EIBMessages.EIB_MC_CONNECT_REQUEST:
             ConnectRequest creq = new ConnectRequest(s);
             _remote_data_endpoint = creq.data_endpoint.endpoint;
             LogReceive("Connect Request");
             ConnectRepsonse cresp = new ConnectRepsonse(_local_endpoint);
             _sock.SendTo(cresp.ToByteArray(),creq.control_endpoint.endpoint);
             LogSend("Connect Response");
             _connected = true;
             break;
         case EIBMessages.EIB_MC_CONNECTION_STATE_REQUEST:
             ConnectionStateRequest csreq = new ConnectionStateRequest(s);
             LogReceive("Connection State Request");
             ConnectionStateResponse csresp = new ConnectionStateResponse();
             _sock.SendTo(csresp.ToByteArray(), csreq.control_endpoint.endpoint);
             LogSend("Connection State Response");
             break;
         case EIBMessages.EIB_MC_DISCONNECT_REQUEST:
             DisconnectRequest disreq = new DisconnectRequest(s);
             LogReceive("Disconnect Request");
             DisconnectResponse disresp = new DisconnectResponse();
             _sock.SendTo(disresp.ToByteArray(), disreq.control_endpoint.endpoint);
             LogSend("Dissconnect Response");
             _restart_now = true;
             _connected = false;
             break;
         case EIBMessages.EIB_MC_SEARCH_REQUEST:
             LogReceive("Search Request");
             SearchRequest sreq = new SearchRequest(s);
             SearchResponse sresp = new SearchResponse(_local_endpoint, _current_if.GetPhysicalAddress());
             _sock.SendTo(sresp.ToByteArray(), sreq._discovery_endpoint.endpoint);
             LogSend("Search Response");
             _connected = true;
             break;
         case EIBMessages.EIB_MC_TUNNEL_REQUEST:
             TunnelRequest req = new TunnelRequest(s);
             if (req._frame._apci == 0x0)
             {
                 string log = String.Format("[Group Read Request] Dest: {0}", req._frame._dst.ToString());
                 LogReceive(log);
             }
             else
             {
                 string log = String.Format("[Tunnel Request] Dest: {0}, Value: 0x{1}", req._frame._dst.ToString(), String.Format("{0:X}", req._frame._apci));
                 LogReceive(log);
             }
             if (req._frame.IsAckNeeded)
             {
                 TunnelAck ack = new TunnelAck(_recv_sequence);
                 _sock.SendTo(ack.ToByteArray(), _remote_data_endpoint);
                 ++_recv_sequence;
                 LogSend("Tunnel Ack");
             }
             TunnelRequest tunnel_request = new TunnelRequest(req._frame, _send_sequence);
             tunnel_request._frame._mc = EIBMessages.L_DATA_CON;
             if (_cache != null)
             {
                 lock (_sync)
                 {
                     foreach (var item in _cache.List)
                     {
                         if (tunnel_request._frame._dst.ToString() == item.Address && item.NumBytes > 1)
                         {
                             tunnel_request._frame._addil_data = new byte[item.NumBytes - 1];
                             tunnel_request._frame._apci_length = (byte)item.NumBytes;
                             break;
                         }
                     }
                 }
             }
             if (req._frame._apci == 0x0)
             {
                 res = true;
             }
             LogSend(String.Format("Tunnel Data confirmation: {0}", tunnel_request._frame._dst.ToString()));
             _sock.SendTo(tunnel_request.ToByteArray(), _remote_data_endpoint);
             break;
         case EIBMessages.EIB_MC_TUNNEL_ACK:
             LogReceive("Ack");
             ++_send_sequence;
             break;
         case EIBMessages.EIB_MC_ROUTING_INDICATION:
             LogReceive("routing indication");
             break;
         default:
             LogReceive("Unknown message code!");
             break;
             //throw new NotImplementedException();
     }
     return res;
 }
Exemplo n.º 2
0
        private bool SendReply(Stream s)
        {
            EIBHeader header = new EIBHeader(s);

            s.Position = 0;
            bool res = false;

            switch (header.mc)
            {
            case EIBMessages.EIB_MC_CONNECT_REQUEST:
                ConnectRequest creq = new ConnectRequest(s);
                _remote_data_endpoint = creq.data_endpoint.endpoint;
                LogReceive("Connect Request");
                ConnectRepsonse cresp = new ConnectRepsonse(_local_endpoint);
                _sock.SendTo(cresp.ToByteArray(), creq.control_endpoint.endpoint);
                LogSend("Connect Response");
                _connected = true;
                break;

            case EIBMessages.EIB_MC_CONNECTION_STATE_REQUEST:
                ConnectionStateRequest csreq = new ConnectionStateRequest(s);
                LogReceive("Connection State Request");
                ConnectionStateResponse csresp = new ConnectionStateResponse();
                _sock.SendTo(csresp.ToByteArray(), csreq.control_endpoint.endpoint);
                LogSend("Connection State Response");
                break;

            case EIBMessages.EIB_MC_DISCONNECT_REQUEST:
                DisconnectRequest disreq = new DisconnectRequest(s);
                LogReceive("Disconnect Request");
                DisconnectResponse disresp = new DisconnectResponse();
                _sock.SendTo(disresp.ToByteArray(), disreq.control_endpoint.endpoint);
                LogSend("Dissconnect Response");
                _restart_now = true;
                _connected   = false;
                break;

            case EIBMessages.EIB_MC_SEARCH_REQUEST:
                LogReceive("Search Request");
                SearchRequest  sreq  = new SearchRequest(s);
                SearchResponse sresp = new SearchResponse(_local_endpoint, _current_if.GetPhysicalAddress());
                _sock.SendTo(sresp.ToByteArray(), sreq._discovery_endpoint.endpoint);
                LogSend("Search Response");
                _connected = true;
                break;

            case EIBMessages.EIB_MC_TUNNEL_REQUEST:
                TunnelRequest req = new TunnelRequest(s);
                if (req._frame._apci == 0x0)
                {
                    string log = String.Format("[Group Read Request] Dest: {0}", req._frame._dst.ToString());
                    LogReceive(log);
                }
                else
                {
                    string log = String.Format("[Tunnel Request] Dest: {0}, Value: 0x{1}", req._frame._dst.ToString(), String.Format("{0:X}", req._frame._apci));
                    LogReceive(log);
                }
                if (req._frame.IsAckNeeded)
                {
                    TunnelAck ack = new TunnelAck(_recv_sequence);
                    _sock.SendTo(ack.ToByteArray(), _remote_data_endpoint);
                    ++_recv_sequence;
                    LogSend("Tunnel Ack");
                }
                TunnelRequest tunnel_request = new TunnelRequest(req._frame, _send_sequence);
                tunnel_request._frame._mc = EIBMessages.L_DATA_CON;
                if (_cache != null)
                {
                    lock (_sync)
                    {
                        foreach (var item in _cache.List)
                        {
                            if (tunnel_request._frame._dst.ToString() == item.Address && item.NumBytes > 1)
                            {
                                tunnel_request._frame._addil_data  = new byte[item.NumBytes - 1];
                                tunnel_request._frame._apci_length = (byte)item.NumBytes;
                                break;
                            }
                        }
                    }
                }
                if (req._frame._apci == 0x0)
                {
                    res = true;
                }
                LogSend(String.Format("Tunnel Data confirmation: {0}", tunnel_request._frame._dst.ToString()));
                _sock.SendTo(tunnel_request.ToByteArray(), _remote_data_endpoint);
                break;

            case EIBMessages.EIB_MC_TUNNEL_ACK:
                LogReceive("Ack");
                ++_send_sequence;
                break;

            case EIBMessages.EIB_MC_ROUTING_INDICATION:
                LogReceive("routing indication");
                break;

            default:
                LogReceive("Unknown message code!");
                break;
                //throw new NotImplementedException();
            }
            return(res);
        }