/// <summary>
        /// Returns Association View.
        /// </summary>
        private byte[] GetObjects()
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Array);
            bool lnExists = ObjectList.FindByLN(ObjectType.AssociationLogicalName, this.LogicalName) != null;
            //Add count
            int cnt = ObjectList.Count();

            if (!lnExists)
            {
                ++cnt;
            }
            GXCommon.SetObjectCount(cnt, data);
            foreach (GXDLMSObject it in ObjectList)
            {
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8((byte)4);                                       //Count
                GXCommon.SetData(data, DataType.UInt16, it.ObjectType);       //ClassID
                GXCommon.SetData(data, DataType.UInt8, it.Version);           //Version
                GXCommon.SetData(data, DataType.OctetString, it.LogicalName); //LN
                GetAccessRights(it, data);                                    //Access rights.
            }
            if (!lnExists)
            {
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8((byte)4);                                         //Count
                GXCommon.SetData(data, DataType.UInt16, this.ObjectType);       //ClassID
                GXCommon.SetData(data, DataType.UInt8, this.Version);           //Version
                GXCommon.SetData(data, DataType.OctetString, this.LogicalName); //LN
                GetAccessRights(this, data);                                    //Access rights.
            }
            return(data.Array());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns Association View.
        /// </summary>
        private byte[] GetObjects()
        {
            List <byte> stream = new List <byte>();

            stream.Add((byte)DataType.Array);
            bool lnExists = ObjectList.FindByLN(ObjectType.AssociationLogicalName, this.LogicalName) != null;
            //Add count
            int cnt = ObjectList.Count();

            if (!lnExists)
            {
                ++cnt;
            }
            GXCommon.SetObjectCount(cnt, stream);
            foreach (GXDLMSObject it in ObjectList)
            {
                stream.Add((byte)DataType.Structure);
                stream.Add((byte)4);                                            //Count
                GXCommon.SetData(stream, DataType.UInt16, it.ObjectType);       //ClassID
                GXCommon.SetData(stream, DataType.UInt8, it.Version);           //Version
                GXCommon.SetData(stream, DataType.OctetString, it.LogicalName); //LN
                GetAccessRights(it, stream);                                    //Access rights.
            }
            if (!lnExists)
            {
                stream.Add((byte)DataType.Structure);
                stream.Add((byte)4);                                              //Count
                GXCommon.SetData(stream, DataType.UInt16, this.ObjectType);       //ClassID
                GXCommon.SetData(stream, DataType.UInt8, this.Version);           //Version
                GXCommon.SetData(stream, DataType.OctetString, this.LogicalName); //LN
                GetAccessRights(this, stream);                                    //Access rights.
            }
            return(stream.ToArray());
        }
Exemplo n.º 3
0
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     //Check reply_to_HLS_authentication
     if (e.Index == 1)
     {
         UInt32 ic = 0;
         byte[] secret;
         if (settings.Authentication == Authentication.HighGMAC)
         {
             secret = settings.SourceSystemTitle;
             GXByteBuffer bb = new GXByteBuffer(e.Parameters as byte[]);
             bb.GetUInt8();
             ic = bb.GetUInt32();
         }
         else
         {
             secret = Secret;
         }
         byte[] serverChallenge = GXSecure.Secure(settings, settings.Cipher, ic, settings.StoCChallenge, secret);
         byte[] clientChallenge = (byte[])e.Parameters;
         if (serverChallenge != null && clientChallenge != null && GXCommon.Compare(serverChallenge, clientChallenge))
         {
             if (settings.Authentication == Authentication.HighGMAC)
             {
                 secret = settings.Cipher.SystemTitle;
                 ic     = settings.Cipher.InvocationCounter;
             }
             else
             {
                 secret = Secret;
             }
             AssociationStatus = AssociationStatus.Associated;
             return(GXSecure.Secure(settings, settings.Cipher, ic, settings.CtoSChallenge, secret));
         }
         else //If the password does not match.
         {
             AssociationStatus = AssociationStatus.NonAssociated;
             return(null);
         }
     }
     else if (e.Index == 2)
     {
         byte[] tmp = e.Parameters as byte[];
         if (tmp == null || tmp.Length == 0)
         {
             e.Error = ErrorCode.ReadWriteDenied;
         }
         else
         {
             Secret = tmp;
         }
     }
     else if (e.Index == 3)
     {
         //Add COSEM object.
         GXDLMSObject obj = GetObject(settings, e.Parameters as object[]);
         //Unknown objects are not add.
         if (obj is IGXDLMSBase)
         {
             if (ObjectList.FindByLN(obj.ObjectType, obj.LogicalName) == null)
             {
                 ObjectList.Add(obj);
             }
             if (settings.Objects.FindByLN(obj.ObjectType, obj.LogicalName) == null)
             {
                 settings.Objects.Add(obj);
             }
         }
     }
     else if (e.Index == 4)
     {
         //Remove COSEM object.
         GXDLMSObject obj = GetObject(settings, e.Parameters as object[]);
         //Unknown objects are not removed.
         if (obj is IGXDLMSBase)
         {
             GXDLMSObject t = ObjectList.FindByLN(obj.ObjectType, obj.LogicalName);
             if (t != null)
             {
                 ObjectList.Remove(t);
             }
             //Item is not removed from all objects. It might be that use wants remove object only from association view.
         }
     }
     else if (e.Index == 5)
     {
         object[] tmp = e.Parameters as object[];
         if (tmp == null || tmp.Length != 2)
         {
             e.Error = ErrorCode.ReadWriteDenied;
         }
         else
         {
             UserList.Add(new KeyValuePair <byte, string>(Convert.ToByte(tmp[0]), Convert.ToString(tmp[1])));
         }
     }
     else if (e.Index == 6)
     {
         object[] tmp = e.Parameters as object[];
         if (tmp == null || tmp.Length != 2)
         {
             e.Error = ErrorCode.ReadWriteDenied;
         }
         else
         {
             UserList.Remove(new KeyValuePair <byte, string>(Convert.ToByte(tmp[0]), Convert.ToString(tmp[1])));
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
     return(null);
 }