private void btnInitiateBond_Click(object sender, EventArgs e)
{
PairBondFieldTabDisable(true);
string str1 = string.Empty;
string str2;
try
{
str2 = tbLongTermKey.Text.Trim();
}
catch (Exception ex)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid Long Term Key Entry.\n '{0}'\nNo Data Was Loaded.\nFormat Is 00:00....\n\n{1}", ex.Message));
tbLongTermKey.Focus();
PairBondUserInputControl();
return;
}
if (str2.Length != 47)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid Long Term Key Length = {0:D} \nLength must be {1:D}", str2.Length, 16));
tbLongTermKey.Focus();
PairBondUserInputControl();
}
else
{
ushort num;
try
{
num = Convert.ToUInt16(tbLTKDiversifier.Text.Trim(), 16);
}
catch (Exception ex)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid LTK Diversifier Entry.\nFormat: 0x0000\n\n{0}\n", ex.Message));
tbLTKDiversifier.Focus();
PairBondUserInputControl();
return;
}
string str3 = string.Empty;
string str4;
try
{
str4 = tbLTKRandom.Text.Trim();
}
catch (Exception ex)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid LTK Random Entry.\n'{0}'\nFormat Is 00:00....\n\n{1}\n", ex.Message));
tbLTKRandom.Focus();
PairBondUserInputControl();
return;
}
if (str4.Length != 23)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid LTK Random Length = {0:D} \nLength must be {1:D}\n", str4.Length, 8));
tbLTKRandom.Focus();
PairBondUserInputControl();
}
else
{
HCICmds.GAPCmds.GAP_Bond gapBond = new HCICmds.GAPCmds.GAP_Bond();
gapBond.connHandle = (ushort)0;
try
{
gapBond.connHandle = Convert.ToUInt16(tbBondConnHandle.Text.Trim(), 16);
}
catch (Exception ex)
{
msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid Connection Handle\n\n{0}\n", ex.Message));
tbBondConnHandle.Focus();
PairBondUserInputControl();
return;
}
gapBond.authenticated = !rbAuthBondTrue.Checked ? HCICmds.GAP_YesNo.No : HCICmds.GAP_YesNo.Yes;
gapBond.secInfo_LTK = str2;
gapBond.secInfo_DIV = num;
gapBond.secInfo_RAND = str4;
ShowProgress(true);
devForm.StartTimer(DeviceForm.EventType.PairBond);
devForm.sendCmds.SendGAP(gapBond);
}
}
}