Archive for September, 2011

RAIDar Protocol Sample

RAIDar Protocol is a communiation way between Netgear RAIDar and ReadyNAS system(s).

Basically, it works like this:

  1. RAIDar periodically sends UDP broadcast having 28 bytes request and destined to port 22081.
  2. On receiving the request, each ReadyNAS system sends back UDP broadcast containing various information on itself.
  3. Then, RAIDar shows the information in its panel (not all information is utilized though).

Here is a sample code developed in VB to retrieve information directly from ReadyNAS system(s) emulating RAIDar Protocol.

Imports System.Globalization
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Friend Shared Function SendRequest() As String()
    'Prepare RAIDar Protocol request.
    '(It must be 28 bytes long while its contest seems not fixed)
    Const request As String = "00 00 07 05 00 00 00 01 00 00 00 00 A4 A1 EF B8 FF FF FF FF 00 00 00 1C 00 00 00 00"
    Dim requestArray As String() = request.Split()

    Dim requestPacket As Byte() = New Byte(27) {}
    For i = 0 To 27
        requestPacket(i) = Byte.Parse(requestArray(i), NumberStyles.HexNumber)

    Dim responses As New List(Of String)()

    'Instantiate UDP Client.
    Using client As New UdpClient()
        'Prepare EndPoint for sending request (Port number of ReadyNAS is fixed).
        Dim sendEP As New IPEndPoint(IPAddress.Broadcast, 22081)

        'Send request.
        client.Send(requestPacket, requestPacket.Length, sendEP)

        'Prepare EndPoint for receiving response.
        Dim receiveEP As New IPEndPoint(IPAddress.Any, 0)

        'Set timeout (3 seconds).
        client.Client.ReceiveTimeout = 3000

        For i = 0 To 10 'Assuming maximum 10 ReadyNAS systems in LAN.
            Dim responsePacket As Byte()

            'Receive response (If no more response, timeout will cause exit).
                responsePacket = client.Receive(receiveEP)
            Catch ex As SocketException
                Exit For
            End Try

            'Check if response has valid length (Leading 28 bytes cannot be correctly decoded to text).
            If (responsePacket.Length <= 28) Then Continue For

            'Decode response to text.
            Dim response As String = Encoding.UTF8.GetString(responsePacket, 28, responsePacket.Length - 28)

            'Remove unnecessary Tab and Lf.
            response = response.Replace(ControlChars.Tab, ControlChars.Lf)
            response = response.Replace(ControlChars.Lf & ControlChars.Lf, ControlChars.Lf)
            response = response.Replace(ControlChars.Lf, Environment.NewLine)

    End Using

    Return responses.ToArray()
End Function

Please note that a system may respond multiple times.

Complete source code