DongleCheck2() | Main Page
Overview
Call DongleCheck2() in a developer's application to return the results of the hash. The K values are the developer's key used in the Set Dongle Key output report. The N values are the random numbers chosen for the hash and also entered for the Check Dongle Key output report. The R values are the returned hash. These R values are compared with those returned from the device immediately following the Check Dongle Key output report. See Dongle Implementation for more details.
PIEDevice.DongleCheck2()
Namespace: PIEHid32NetAssembly: PIEHid32Net.dll
Syntax
C#
public static void DongleCheck2(int k0, int k1, int k2, int k3, int n0, int n1, int n2, int n3, out int r0, out int r1, out int r2, out int r3);
Visual Basic (Declaration)
Public Shared Sub DongleCheck2(ByVal k0 As Integer, ByVal k1 As Integer, ByVal k2 As Integer, ByVal k3 As Integer, ByVal n0 As Integer, ByVal n1 As Integer, ByVal n2 As Integer, ByVal n3 As Integer, ByRef r0 As Integer, ByRef r1 As Integer, ByRef r2 As Integer, ByRef r3 As Integer)
Visual Basic (Usage)
PIEHidDotNet.PIEDevice.DongleCheck2(K0, K1, K2, K3, N0, N1, N2, N3, R0, R1, R2, R3)
Examples
C# private void BtnCheckKey_Click(object sender, EventArgs e) { //This is done within the developer's application to check for the correct //hardware. The K0-K3 values must be the same as those entered in Set Key. LblPassFail.Text = "Pass/Fail"; //check hardware //IMPORTANT turn off the callback if going so data isn't grabbed there, turn it back on later (not done here) devices[selecteddevice].callNever = true; //randomn numbers Random rnd = new Random(); int N0 = rnd.Next(1, 254); //pick any number between 1 and 254, 0 and 255 not allowed int N1 = rnd.Next(1, 254); //pick any number between 1 and 254, 0 and 255 not allowed int N2 = rnd.Next(1, 254); //pick any number between 1 and 254, 0 and 255 not allowed int N3 = rnd.Next(1, 254); //pick any number between 1 and 254, 0 and 255 not allowed //this is the key used in the Set Dongle Key output report int K0 = 7; int K1 = 58; int K2 = 33; int K3 = 243; //hash and save these for comparison later int R0; int R1; int R2; int R3; PIEDevice.DongleCheck2(K0, K1, K2, K3, N0, N1, N2, N3, out R0, out R1, out R2, out R3); for (int j = 0; j < devices[selecteddevice].WriteLength; j++) { wData[j] = 0; } wData[0] = 0; wData[1] = 193; //Check Dongle Key command wData[2] = (byte)N0; wData[3] = (byte)N1; wData[4] = (byte)N2; wData[5] = (byte)N3; int result = devices[selecteddevice].WriteData(wData); if (result != 0) { toolStripStatusLabel1.Text = "Write Fail: " + result; } else { toolStripStatusLabel1.Text = "Write Success-Check Dongle Key"; } //after this write the next read with the 3rd byte=193 will give 4 values which are used below for comparison byte[] data =null; int countout = 0; int ret = devices[selecteddevice].BlockingReadData(ref data, 100); while ((ret == 0 && data[2] != 193) || ret == 304) { if (ret == 304) { // Didn't get any data for 100ms, increment the countout extra countout += 100; } countout++; if (countout > 500) //increase this if have to check more than once break; ret = devices[selecteddevice].BlockingReadData(ref data, 100); } if (ret == 0 && data[2] == 193) { bool fail = false; if (R0 != data[3]) fail = true; if (R1 != data[4]) fail = true; if (R2 != data[5]) fail = true; if (R3 != data[6]) fail = true; if (fail == false) { LblPassFail.Text = "Pass-Correct Hardware Found"; } else { LblPassFail.Text = "Fail-Correct Hardward Not Found"; } } }
Visual Basic Private Sub BtnCheckKey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCheckKey.Click 'This is done within the developer's application to check for the correct 'hardware. The K0-K3 values must be the same as those entered in Set Key. 'Check hardware 'IMPORTANT turn off the callback if going so data isn't grabbed there, turn it back on later (not done here) devices(selecteddevice).callNever = True 'pick 4 randomn numbers between 1 and 254 Randomize() Dim N0 As Integer = CInt(Int((254 * Rnd()) + 1)) 'random number between 1 and 254 Dim N1 As Integer = CInt(Int((254 * Rnd()) + 1)) 'random number between 1 and 254 Dim N2 As Integer = CInt(Int((254 * Rnd()) + 1)) 'random number between 1 and 254 Dim N3 As Integer = CInt(Int((254 * Rnd()) + 1)) 'random number between 1 and 254 'this is the key from the Set Key Dim K0 As Integer = 7 Dim K1 As Integer = 58 Dim K2 As Integer = 33 Dim K3 As Integer = 243 'hash and save these for comparison later Dim R0 As Integer Dim R1 As Integer Dim R2 As Integer Dim R3 As Integer PIEHidDotNet.PIEDevice.DongleCheck2(K0, K1, K2, K3, N0, N1, N2, N3, R0, R1, R2, R3) For i As Integer = 0 To devices(selecteddevice).WriteLength - 1 wdata(i) = 0 Next wdata(0) = 0 wdata(1) = 193 'Check Dongle Key command wdata(2) = N0 wdata(3) = N1 wdata(4) = N2 wdata(5) = N3 Dim result As Integer = devices(selecteddevice).WriteData(wdata) If result <> 0 Then LblStatus.Text = "Write Fail: " + result.ToString Else LblStatus.Text = "Write Success - Check Key" End If 'after this write the next read with 3rd byte=193 will give 4 values which are used below for comparison Dim ddata(devices(selecteddevice).ReadLength) As Byte Dim countout As Integer = 0 result = devices(selecteddevice).BlockingReadData(ddata, 100) While (result = 304 Or (result = 0 And ddata(2) <> 193)) If result = 304 Then 'no new data after 100ms, so increment countout extra countout = countout + 99 End If countout = countout + 1 If (countout > 1000) Then Exit While End If result = devices(selecteddevice).BlockingReadData(ddata, 100) End While If result = 0 And ddata(2) = 193 Then Dim fail As Boolean = False If R0 <> ddata(3) Then fail = True If R1 <> ddata(4) Then fail = True If R2 <> ddata(5) Then fail = True If R3 <> ddata(6) Then fail = True If fail = False Then LblPassFail.Text = "Pass-Correct Hardware Found" If fail = True Then LblPassFail.Text = "Fail-Correct Hardware Not Found" End If End Sub
Unmanaged DLL
CheckDongle2 Function
Syntax
VOID __stdcall DongleCheck2(int K0, int K1, int K2, int K3, int N0, int N1, int N2, int N3, int &R0, int &R1, int &R2, int &R3);
Parameters
K0 [in]. The first key value used when writing a dongle key to a device using the Set Dongle Key output report.
K1 [in]. The second key value used when writing a dongle key to a device using the Set Dongle Key output report.
K2 [in]. The third key value used when writing a dongle key to a device using the Set Dongle Key output report.
K3 [in]. The fourth key value used when writing a dongle key to a device using the Set Dongle Key output report.
N0 [in]. A randomn number between 1 and 254 used when checking a dongle key using the Check Dongle Key output report.
N1 [in]. A randomn number between 1 and 254 used when checking a dongle key using the Check Dongle Key output report.
N2 [in]. A randomn number between 1 and 254 used when checking a dongle key using the Check Dongle Key output report.
N3 [in]. A randomn number between 1 and 254 used when checking a dongle key using the Check Dongle Key output report.
R0 [out]. Return value to be compared with the data read immediatly following a Check Dongle Key output report.
R1 [out]. Return value to be compared with the data read immediatly following a Check Dongle Key output report.
R2 [out]. Return value to be compared with the data read immediatly following a Check Dongle Key output report.
R3 [out]. Return value to be compared with the data read immediatly following a Check Dongle Key output report.
Return Value
No return value.
Example
C++ ... //This is done within the developer's application to check for the correct //hardware. The K0-K3 values must be the same as those entered in Set Dongle Key. if (hDevice == -1) return TRUE; //check hardware //IMPORTANT turn off the callback if going so data isn't grabbed there, turn it back on later (not done here) DisableDataCallback(hDevice, true); //randomn numbers int N0 = 3; //pick any number between 1 and 254 int N1 = 1; //pick any number between 1 and 254 int N2 = 4; //pick any number between 1 and 254 int N3 = 1; //pick any number between 1 and 254 //this is the key from set key K0 = 7; K1 = 58; K2 = 33; K3 = 243; //hash and save these for comparison later int R0; int R1; int R2; int R3; DongleCheck2(K0, K1, K2, K3, N0, N1, N2, N3, R0, R1, R2, R3); for (i=0;i<36;i++) { buffer[i]=0; } buffer[0]=0;
buffer[1]=193; //0xc1 check dongle key command buffer[2]=N0; buffer[3]=N1; buffer[4]=N2; buffer[5]=N3; result = WriteData(hDevice, buffer); //after this write the next read beginning with byte 1=3 will give 4 values which are used below for comparison for (int i=0;i<80;i++) {buffer[i]=0;} int countout=0; int result = BlockingReadData(hDevice, buffer, 100); while (result == 304 || (result == 0 && buffer[2] != 193)) { if (result == 304) { // No data received after 100ms, so increment countout extra countout += 99; } countout++; if (countout > 1000) //increase this if have to check more than once break; result = BlockingReadData(hDevice, buffer, 100); } if (result ==0 && buffer[2]==193) { bool fail=false; if (R0!=buffer[3]) fail=true; if (R1!=buffer[4]) fail=true; if (R2!=buffer[5]) fail=true; if (R3!=buffer[6]) fail=true; }
Remarks
Not all P.I. Engineering products have dongle support, check your product's data reports to see if dongle support is available. The Check Dongle Key output report and Check Dongle Key input report may vary from product to product, check your product's data reports before using.
Function Information
Back to topMinimum DLL Version: PIEHid32.dll
Header: PIEHid32.h
Import Library: PIEHid32.lib