Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2022 lines
60 KiB

  1. /*-------------------------------------------------------------------
  2. | devprop.c - Device Properties Sheet.
  3. 5-26-99 - fix picking inappropriate starting com-port index.
  4. 2-02-99 - fix port rename problem, where it would skip over old port-names,
  5. also take out port-name from selection if owned by other drivers.
  6. |--------------------------------------------------------------------*/
  7. #include "precomp.h"
  8. #define D_Level 0x20
  9. // use a current and previous reading to measure the advance, or
  10. // calculated value. Drop occassional rollover case.
  11. #define NORM_COUNTER(calc,curr,prev,last) \
  12. { \
  13. if ((curr) > (prev)) \
  14. calc = (last) + ((curr) - (prev)); \
  15. else \
  16. calc = (last); \
  17. }
  18. //#define STATE_DISPLAY 1
  19. #ifdef STATE_DISPLAY
  20. #define STATE_CHANGE(newstate) \
  21. { \
  22. mess(&wi->ip, \
  23. "Currstate %s\nNewstate %s\n", \
  24. statestrings[pDstatus->verbose_advise_state], \
  25. statestrings[(newstate)]); \
  26. pDstatus->verbose_advise_state = (newstate); \
  27. }
  28. #else
  29. #define STATE_CHANGE(newstate) \
  30. { \
  31. pDstatus->verbose_advise_state = (newstate); \
  32. }
  33. #endif
  34. static void set_field(HWND hDlg, WORD id);
  35. static void get_field(HWND hDlg, WORD id);
  36. static int PaintIcon(HWND hWnd);
  37. static int PaintLogo(HWND hWnd);
  38. static int set_mac_field(HWND hDlg, WORD id);
  39. static int set_io_addr_field(HWND hDlg, WORD id);
  40. #define MAX_DEVPROP_SHEETS 2
  41. typedef struct
  42. {
  43. int x;
  44. int y;
  45. } POINT2D;
  46. static int PaintRockers(HWND hWnd, int brd);
  47. static int poly_border(POINT2D *pts, POINT2D *ends, int lines);
  48. static void draw_but(HDC hDC, int x, int y, int cx, int cy, int but_in);
  49. static int num_active_devprop_sheets = 1; // always at least one
  50. #ifdef S_VS
  51. typedef struct {
  52. unsigned char mac[6];
  53. unsigned char flags;
  54. unsigned char nic_index;
  55. }DRIVER_MAC_STATUS;
  56. typedef struct {
  57. ULONG struct_size;
  58. ULONG num_ports;
  59. ULONG total_loads;
  60. ULONG good_loads;
  61. ULONG backup_server;
  62. ULONG state;
  63. ULONG iframes_sent;
  64. ULONG rawframes_sent; // was send_rawframes
  65. ULONG ctlframes_sent; // was send_ctlframes
  66. ULONG iframes_resent; // was pkt_resends
  67. ULONG iframes_outofseq; // was ErrBadIndex
  68. ULONG frames_rcvd; // was: rec_pkts
  69. ULONG nic_index;
  70. unsigned char dest_addr[6];
  71. } PROBE_DEVICE_STRUCT;
  72. typedef struct {
  73. ULONG struct_size;
  74. ULONG Open;
  75. ULONG pkt_sent;
  76. ULONG pkt_rcvd_ours;
  77. ULONG pkt_rcvd_not_ours;
  78. char NicName[64];
  79. unsigned char address[6];
  80. } PROBE_NIC_STRUCT;
  81. typedef struct {
  82. int verbose_advise_state; // index into big advise string
  83. int vsl_detected; // number of vs's found from broadcast ping
  84. int vsl_available; // number of vs's available found from broadcast ping
  85. BYTE vsl_load_status; // flags info come back from broadcast query replys
  86. BYTE vsl_device_status_found; // 1=driver found matching VS config.
  87. BYTE vsl_nic_status_found; // 1=driver found NIC config.
  88. BYTE vsl_driver_found; // 1=we can talk to driver, 0=driver not loaded
  89. BYTE vsl_ping_device_found; // 1=we found it during a ping
  90. BYTE vsl_mac_list_found; // 1=ping delivered a list of macs on network
  91. PROBE_NIC_STRUCT curr_nic;
  92. PROBE_NIC_STRUCT prev_nic;
  93. PROBE_NIC_STRUCT calc_nic;
  94. PROBE_NIC_STRUCT temp_nic;
  95. PROBE_DEVICE_STRUCT curr_dev;
  96. PROBE_DEVICE_STRUCT prev_dev;
  97. PROBE_DEVICE_STRUCT calc_dev;
  98. PROBE_DEVICE_STRUCT temp_dev;
  99. } DSTATUS;
  100. #define FLAG_APPL_RUNNING 0x01
  101. #define FLAG_NOT_OWNER 0x02
  102. #define FLAG_OWNER_TIMEOUT 0x04
  103. static void set_status_field(HWND hDlg,WORD id,DSTATUS *pDstatus);
  104. static void check_traffic_activity(DSTATUS *pDstatus);
  105. static void get_status(DSTATUS *pDstatus,int reset);
  106. static BYTE *ping_devices(DSTATUS *pDstatus, int *nBytes);
  107. static void build_advisor_display(HWND hDlg,DSTATUS *pDstatus,int reset);
  108. char *vslink_state_table[] = { // 27 May BF
  109. "Init",
  110. "InitOwn",
  111. "SendCode",
  112. "Connect",
  113. "Active",
  114. "Invalid",
  115. };
  116. #define VSL_STATE_INIT 0
  117. #define VSL_STATE_INITOWN 1
  118. #define VSL_STATE_SENDCODE 2
  119. #define VSL_STATE_CONNECT 3
  120. #define VSL_STATE_ACTIVE 4
  121. // these values are used in port.c in the driver:
  122. //#define ST_INIT 0
  123. //#define ST_GET_OWNERSHIP 1
  124. //#define ST_SENDCODE 2
  125. //#define ST_CONNECT 3
  126. //#define ST_ACTIVE 4
  127. #define NIC_STATE_INVALID 0
  128. #define NIC_STATE_CLOSED 1
  129. #define NIC_STATE_OPEN 2
  130. #define NIC_STATE_UNDEFINED 3
  131. #define STATE_not_init 0
  132. #define STATE_driver_not_avail 1
  133. #define STATE_nic_not_avail 2
  134. #define STATE_no_vslinks_avail 3
  135. #define STATE_vslink_not_avail 4
  136. #define STATE_not_configured 5
  137. #define STATE_not_owner 6
  138. #define STATE_vslink_not_ready 7
  139. #define STATE_ok_no_traffic 8
  140. #define STATE_ok 9
  141. #define STATE_poor_link 10
  142. #define STATE_reset 11
  143. //#define STATE_network_not_avail
  144. #if 0
  145. char *AdvisoryString[] = { // 27 May BF
  146. /* 1 */ "Device is active and OK.",
  147. /* 2 */ "No data traffic exchanged since last inquiry.",
  148. #endif
  149. char *AdvisoryString[] = { // 27 May BF
  150. "Uninitialized.",
  151. "The driver is not running. If you just installed the driver \
  152. you will need to exit the program before the driver starts.",
  153. "Unable to find a Network Interface Controller (NIC) card.",
  154. "Can't detect any Comtrol devices. Check Ethernet connectors and insure \
  155. device is powered on.",
  156. "Can't detect device with specified MAC address on any network. Verify MAC \
  157. address of unit, check Ethernet connectors and insure device is powered on.",
  158. "Device with specified MAC address was detected, but isn't configured for \
  159. this server. Return to 'Device Setup' dialog, configure, save configuration, \
  160. and restart server.",
  161. "Device detected and is configured for this server, but is not yet assigned \
  162. to this server.",
  163. "Device detected, initializing.",
  164. "Device is active and OK, no data traffic exchanged since last inquiry.",
  165. "Device is active and OK.",
  166. "Poor connection to device. Check connectors, cabling, and insure proper LAN \
  167. termination.",
  168. "Counts reset.",
  169. };
  170. static int dstatus_initialized = 0;
  171. static DSTATUS glob_dstatus;
  172. #endif
  173. int FillDevicePropSheets(PROPSHEETPAGE *psp, LPARAM our_params);
  174. BOOL WINAPI DevicePropSheet(
  175. IN HWND hDlg,
  176. IN UINT uMessage,
  177. IN WPARAM wParam,
  178. IN LPARAM lParam);
  179. BOOL WINAPI StatusPropSheet( // 27 May BF
  180. IN HWND hDlg,
  181. IN UINT uMessage,
  182. IN WPARAM wParam,
  183. IN LPARAM lParam);
  184. /*------------------------------------------------------------------------
  185. | FillDevicePropSheets - Setup pages for driver level property sheets.
  186. |------------------------------------------------------------------------*/
  187. int FillDevicePropSheets(PROPSHEETPAGE *psp, LPARAM our_params)
  188. {
  189. INT pi;
  190. static TCHAR devsetstr[40], devadvstr[40];
  191. memset(psp, 0, sizeof(*psp) * MAX_DEVPROP_SHEETS);
  192. pi = 0;
  193. // prop device sheet.
  194. psp[pi].dwSize = sizeof(PROPSHEETPAGE);
  195. //psp[pi].dwFlags = PSP_USEICONID | PSP_USETITLE;
  196. psp[pi].dwFlags = PSP_USETITLE | PSP_HASHELP;
  197. psp[pi].hInstance = glob_hinst;
  198. #ifdef S_VS
  199. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_VS_DEVICE_SETUP);
  200. #else
  201. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_DEVICE_SETUP);
  202. #endif
  203. psp[pi].pfnDlgProc = DevicePropSheet;
  204. load_str( glob_hinst, (TITLESTR+1), devsetstr, CharSizeOf(devsetstr) );
  205. psp[pi].pszTitle = devsetstr;
  206. psp[pi].lParam = (LPARAM)our_params;
  207. psp[pi].pfnCallback = NULL;
  208. ++pi;
  209. num_active_devprop_sheets = 1;
  210. #ifdef S_VS
  211. // prop status sheet.
  212. psp[pi].dwSize = sizeof(PROPSHEETPAGE);
  213. //psp[pi].dwFlags = PSP_USEICONID | PSP_USETITLE;
  214. psp[pi].dwFlags = PSP_USETITLE | PSP_HASHELP;
  215. psp[pi].hInstance = glob_hinst;
  216. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_STATUS);
  217. psp[pi].pfnDlgProc = StatusPropSheet;
  218. load_str( glob_hinst, (TITLESTR+2), devadvstr, CharSizeOf(devadvstr) );
  219. psp[pi].pszTitle = devadvstr;
  220. psp[pi].lParam = (LPARAM)our_params;
  221. psp[pi].pfnCallback = NULL;
  222. ++pi;
  223. ++num_active_devprop_sheets;
  224. #endif
  225. return 0;
  226. }
  227. /*------------------------------------------------------------------------
  228. | DoDevicePropPages - Main driver level property sheet for NT4.0
  229. |------------------------------------------------------------------------*/
  230. int DoDevicePropPages(HWND hwndOwner)
  231. {
  232. PROPSHEETPAGE psp[MAX_DEVPROP_SHEETS];
  233. PROPSHEETHEADER psh;
  234. OUR_INFO *our_params;
  235. INT stat;
  236. static TCHAR devpropstr[40];
  237. our_params = glob_info; // temporary kludge, unless we don't need re-entrantancy
  238. //Fill out the PROPSHEETPAGE data structure for the Client Area Shape
  239. //sheet
  240. FillDevicePropSheets(&psp[0], (LPARAM)our_params);
  241. //Fill out the PROPSHEETHEADER
  242. memset(&psh, 0, sizeof(PROPSHEETHEADER));
  243. psh.dwSize = sizeof(PROPSHEETHEADER);
  244. //psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE;
  245. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  246. psh.hwndParent = hwndOwner;
  247. psh.hInstance = glob_hinst;
  248. psh.pszIcon = "";
  249. load_str( glob_hinst, (TITLESTR+9), devpropstr, CharSizeOf(devpropstr) );
  250. psh.pszCaption = devpropstr;
  251. psh.nPages = num_active_devprop_sheets;
  252. psh.ppsp = (LPCPROPSHEETPAGE) &psp;
  253. #ifdef S_VS
  254. if (!dstatus_initialized)
  255. {
  256. dstatus_initialized = 1;
  257. memset(&glob_dstatus, 0, sizeof(glob_dstatus));
  258. //establish a base point for packet stats...
  259. get_status(&glob_dstatus,0);
  260. }
  261. #endif
  262. //And finally display the dialog with the property sheets.
  263. stat = PropertySheet(&psh);
  264. return 0;
  265. }
  266. /*----------------------------------------------------------
  267. DevicePropSheet - Dlg window procedure for add on Advanced sheet.
  268. |-------------------------------------------------------------*/
  269. BOOL WINAPI DevicePropSheet(
  270. IN HWND hDlg,
  271. IN UINT uMessage,
  272. IN WPARAM wParam,
  273. IN LPARAM lParam)
  274. {
  275. OUR_INFO *OurProps = (OUR_INFO *)GetWindowLong(hDlg, DWL_USER);
  276. //UINT stat;
  277. WORD uCmd;
  278. HWND hwnd;
  279. switch(uMessage)
  280. {
  281. case WM_INITDIALOG :
  282. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  283. SetWindowLong(hDlg, DWL_USER, (LONG)OurProps);
  284. // save in case of cancel
  285. //memcpy(&org_dev, &wi->dev[glob_info->device_selected], sizeof(org_dev));
  286. set_field(hDlg, IDC_EB_NAME);
  287. #ifdef S_VS
  288. set_field(hDlg, IDC_CBOX_NUMPORTS);
  289. #endif
  290. set_field(hDlg, IDC_CBOX_SC);
  291. #ifdef S_VS
  292. set_field(hDlg, IDC_CBOX_MACADDR);
  293. set_field(hDlg, IDC_BACKUP_SERVER);
  294. set_field(hDlg, IDC_BACKUP_TIMER);
  295. #else
  296. #if (defined(NT50) && defined(S_RK))
  297. // if nt50 and rocketport then get rid of io-address field as
  298. // nt takes care of io-allocation for us.
  299. ShowWindow(GetDlgItem(hDlg, IDC_CBOX_IOADDR), SW_HIDE);
  300. ShowWindow(GetDlgItem(hDlg, IDL_ISA_BUS_LABEL), SW_HIDE);
  301. ShowWindow(GetDlgItem(hDlg, IDL_BASE_ADDR_LABEL), SW_HIDE);
  302. #endif
  303. set_field(hDlg, IDC_CBOX_IOADDR);
  304. set_field(hDlg, IDC_LBL_SUMMARY1);
  305. set_field(hDlg, IDC_LBL_SUMMARY2);
  306. #endif
  307. return TRUE; // No need for us to set the focus.
  308. case WM_COMMAND:
  309. uCmd = HIWORD(wParam);
  310. switch (LOWORD(wParam))
  311. {
  312. case IDC_BACKUP_SERVER:
  313. //--- enable or disable backup-timer field depending on backup server[]
  314. hwnd = GetDlgItem(hDlg, IDC_BACKUP_TIMER);
  315. if (IsDlgButtonChecked(hDlg, IDC_BACKUP_SERVER))
  316. EnableWindow(hwnd,1);
  317. else EnableWindow(hwnd,0);
  318. break;
  319. #ifdef S_RK
  320. #if (!defined(NT50))
  321. case IDC_CBOX_IOADDR:
  322. if (uCmd == CBN_SELCHANGE)
  323. {
  324. get_field(hDlg, IDC_CBOX_IOADDR);
  325. PaintRockers(hDlg, glob_info->device_selected);
  326. }
  327. break;
  328. #endif
  329. #endif
  330. }
  331. return FALSE;
  332. case WM_PAINT:
  333. PaintIcon(hDlg);
  334. #ifdef S_RK
  335. PaintLogo(GetDlgItem(hDlg, IDC_RKT_LOGO));
  336. #else
  337. PaintLogo(GetDlgItem(hDlg, IDC_VS_LOGO));
  338. #endif
  339. #ifdef S_RK
  340. #if (!defined(NT50))
  341. PaintRockers(hDlg, glob_info->device_selected);
  342. #endif
  343. #endif
  344. return FALSE;
  345. case WM_HELP:
  346. our_context_help(lParam);
  347. return FALSE;
  348. case WM_NOTIFY :
  349. switch (((NMHDR *)lParam)->code)
  350. {
  351. case PSN_HELP :
  352. #ifdef S_VS
  353. our_help(&wi->ip, IDD_VS_DEVICE_SETUP);
  354. #else
  355. our_help(&wi->ip, IDD_DEVICE_SETUP);
  356. #endif
  357. break;
  358. case PSN_APPLY :
  359. get_field(hDlg, IDC_EB_NAME);
  360. get_field(hDlg, IDC_CBOX_SC);
  361. #ifdef S_VS
  362. get_field(hDlg, IDC_CBOX_NUMPORTS);
  363. get_field(hDlg, IDC_CBOX_MACADDR);
  364. get_field(hDlg, IDC_BACKUP_SERVER);
  365. get_field(hDlg, IDC_BACKUP_TIMER);
  366. #else
  367. get_field(hDlg, IDC_CBOX_IOADDR);
  368. #endif
  369. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  370. return TRUE;
  371. default :
  372. return FALSE;
  373. }
  374. break;
  375. default :
  376. // return FALSE;
  377. break;
  378. }
  379. return FALSE;
  380. }
  381. /*----------------------------------------------------------
  382. set_field -
  383. |------------------------------------------------------------*/
  384. static void set_field(HWND hDlg, WORD id)
  385. {
  386. HWND hwnd;
  387. char tmpstr[60];
  388. Device_Config *dev;
  389. int i;
  390. dev = &wi->dev[glob_info->device_selected];
  391. switch(id)
  392. {
  393. case IDC_EB_NAME:
  394. SetDlgItemText(hDlg, id, dev->Name);
  395. break;
  396. case IDC_LBL_SUMMARY1:
  397. wsprintf(tmpstr, "%s - %d ",
  398. dev->ModelName,
  399. dev->NumPorts);
  400. if (dev->IoAddress == 1)
  401. strcat(tmpstr, "PCI");
  402. else
  403. strcat(tmpstr, "ISA");
  404. SetDlgItemText(hDlg, id, tmpstr);
  405. break;
  406. case IDC_LBL_SUMMARY2:
  407. strcpy(tmpstr,"");
  408. if (dev->ModemDevice == TYPE_RM_VS2000) {
  409. for (
  410. i = 0;
  411. i < NUM_ROW_COUNTRIES;
  412. i++
  413. ) {
  414. if (wi->ModemCountry == RowInfo[i].RowCountryCode)
  415. break;
  416. }
  417. wsprintf(
  418. tmpstr,
  419. "Configured for: %s",
  420. (i == NUM_ROW_COUNTRIES) ? RowInfo[0].RowCountryName : RowInfo[i].RowCountryName);
  421. }
  422. else if (dev->ModemDevice == TYPE_RM_i) {
  423. strcpy(tmpstr,CTRRowInfo[0].RowCountryName); // default
  424. for (
  425. i = 0;
  426. i < NUM_CTR_ROW_COUNTRIES;
  427. i++
  428. ) {
  429. if (wi->ModemCountry == CTRRowInfo[i].RowCountryCode)
  430. break;
  431. }
  432. wsprintf(
  433. tmpstr,
  434. "Configured for: %s",
  435. (i == NUM_CTR_ROW_COUNTRIES) ? CTRRowInfo[0].RowCountryName : CTRRowInfo[i].RowCountryName);
  436. }
  437. else if (dev->ModemDevice) {
  438. wsprintf(
  439. tmpstr,
  440. "Configured for: %s",
  441. RowInfo[0].RowCountryName);
  442. }
  443. SetDlgItemText(hDlg, id, tmpstr);
  444. break;
  445. #ifdef S_VS
  446. case IDC_CBOX_NUMPORTS:
  447. hwnd = GetDlgItem(hDlg, id);
  448. if (dev->ModemDevice)
  449. {
  450. DbgPrintf(D_Test, ("vs2000 fill\n"))
  451. // VS2000 only available in 8 port configuration
  452. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP8);
  453. }
  454. else if (dev->HubDevice)
  455. {
  456. DbgPrintf(D_Test, ("hubdev fill\n"))
  457. // SerialHub available in 4 (not yet) and 8 port configuration
  458. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP4);
  459. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP8);
  460. // default the number of ports for the Serial Hub to 8
  461. }
  462. else
  463. {
  464. DbgPrintf(D_Test, ("vs fill\n"))
  465. // we must have a VS1000 or VS1000/VS1100 combo
  466. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP16);
  467. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP32);
  468. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP48);
  469. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)szNP64);
  470. }
  471. wsprintf(tmpstr, "%d", dev->NumPorts);
  472. SendMessage(hwnd, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)(char far *) tmpstr);
  473. break;
  474. #endif
  475. #ifdef S_VS
  476. case IDC_CBOX_MACADDR:
  477. set_mac_field(hDlg, id);
  478. break;
  479. #endif
  480. case IDC_CBOX_SC:
  481. //---------------------- setup starting com port
  482. hwnd = GetDlgItem(hDlg, IDC_CBOX_SC);
  483. {
  484. int foundName = 0;
  485. int pi = 0;
  486. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  487. for (i=1; i<1024; i++)
  488. {
  489. wsprintf(tmpstr,"COM%d", i);
  490. if ((!IsPortNameInSetupUse(tmpstr)) && // not ours already
  491. (IsPortNameInRegUse(tmpstr) == 1)) // not ours in registry
  492. {
  493. // someone elses name, don't put in our list
  494. }
  495. else
  496. {
  497. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM) tmpstr);
  498. if ((foundName == 0) &&(_tcsicmp(tmpstr, dev->ports[0].Name) == 0))
  499. {
  500. foundName = pi;
  501. }
  502. ++pi;
  503. }
  504. }
  505. SendMessage(hwnd, CB_SETCURSEL, foundName, (LPARAM)0);
  506. // this was setting "COM300" from list instead of "COM3" for some reason
  507. // under NT2000, So go back to index way. kpb, 5-26-99
  508. //SendMessage(hwnd, CB_SELECTSTRING, 0, (LPARAM)dev->ports[0].Name);
  509. }
  510. break;
  511. case IDC_BACKUP_SERVER:
  512. //------------------ fill in "BackupServer" option
  513. SendDlgItemMessage(hDlg, IDC_BACKUP_SERVER, BM_SETCHECK, dev->BackupServer, 0);
  514. //--- enable or disable backup-timer field depending on backup server[]
  515. hwnd = GetDlgItem(hDlg, IDC_BACKUP_TIMER);
  516. if (IsDlgButtonChecked(hDlg, IDC_BACKUP_SERVER))
  517. EnableWindow(hwnd,1);
  518. else EnableWindow(hwnd,0);
  519. break;
  520. case IDC_BACKUP_TIMER:
  521. //------------------ fill in backup timer selection
  522. hwnd = GetDlgItem(hDlg, IDC_BACKUP_TIMER);
  523. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  524. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "2 min");
  525. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "5 min");
  526. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "10 min");
  527. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "30 min");
  528. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "60 min");
  529. if (dev->BackupTimer < 2) dev->BackupTimer = 2; // 2 minute, no less
  530. wsprintf(tmpstr, "%d min", dev->BackupTimer);
  531. SetDlgItemText(hDlg, IDC_BACKUP_TIMER, tmpstr);
  532. break;
  533. case IDC_CBOX_IOADDR:
  534. set_io_addr_field(hDlg, id);
  535. break;
  536. }
  537. }
  538. /*-------------------------------------------------------------------
  539. | get_field -
  540. |--------------------------------------------------------------------*/
  541. static void get_field(HWND hDlg, WORD id)
  542. {
  543. char tmpstr[60];
  544. Device_Config *dev;
  545. int stat, i, chk;
  546. int val;
  547. dev = &wi->dev[glob_info->device_selected];
  548. switch (id)
  549. {
  550. case IDC_EB_NAME:
  551. GetDlgItemText(hDlg, IDC_EB_NAME, dev->Name, 59);
  552. break;
  553. #ifdef S_VS
  554. case IDC_CBOX_NUMPORTS:
  555. {
  556. int bad = 0;
  557. GetDlgItemText(hDlg, id, tmpstr, 19);
  558. stat= sscanf(tmpstr,"%ld",&val);
  559. if ((stat == 1) && (val >= 0))
  560. {
  561. if (val == 4)
  562. dev->NumPorts = (int) val;
  563. else if (val == 8)
  564. dev->NumPorts = (int) val;
  565. else if (val == 16)
  566. dev->NumPorts = (int) val;
  567. else if (val == 32)
  568. dev->NumPorts = (int) val;
  569. else if (val == 48)
  570. dev->NumPorts = (int) val;
  571. else if (val == 64)
  572. dev->NumPorts = (int) val;
  573. else
  574. bad = 1;
  575. }
  576. else
  577. {
  578. bad = 1;
  579. dev->NumPorts = 16;
  580. }
  581. if (bad)
  582. {
  583. our_message(&wi->ip,RcStr(MSGSTR),MB_OK);
  584. //ret_stat = 1;
  585. }
  586. }
  587. break;
  588. #endif
  589. #ifdef S_VS
  590. case IDC_CBOX_MACADDR:
  591. get_mac_field(hDlg, id, dev->MacAddr);
  592. break;
  593. #endif
  594. case IDC_CBOX_SC:
  595. GetDlgItemText(hDlg, id, tmpstr, 58);
  596. if (_tcsicmp(tmpstr, dev->ports[0].Name) != 0) //changed
  597. {
  598. //StartComIndex = getint(&tmpstr[3], &i); // COM# num
  599. for (i=0; i<dev->NumPorts; i++)
  600. {
  601. strcpy(dev->ports[i].Name, tmpstr); // put in new name
  602. BumpPortName(tmpstr);
  603. // if its not our name already
  604. if (!IsPortNameInSetupUse(tmpstr))
  605. {
  606. chk = 0;
  607. // keep picking new name if this name is already
  608. // owned based on the names exported in the registry.
  609. while ((IsPortNameInRegUse(tmpstr) == 1) && (chk < 1024))
  610. {
  611. BumpPortName(tmpstr);
  612. ++chk;
  613. }
  614. }
  615. }
  616. }
  617. break;
  618. case IDC_BACKUP_SERVER:
  619. //------------------ get the backup server chk box.
  620. if (IsDlgButtonChecked(hDlg, IDC_BACKUP_SERVER))
  621. dev->BackupServer = 1;
  622. else dev->BackupServer = 0;
  623. break;
  624. case IDC_BACKUP_TIMER:
  625. //------------------ get the backup timer value
  626. //bad = 0;
  627. GetDlgItemText(hDlg, id, tmpstr, 19);
  628. stat= sscanf(tmpstr,"%ld",&val);
  629. if (stat == 1)
  630. dev->BackupTimer = val;
  631. if (dev->BackupTimer < 2)
  632. dev->BackupTimer = 2;
  633. break;
  634. case IDC_CBOX_IOADDR:
  635. //------------------ get the io-address
  636. GetDlgItemText(hDlg, IDC_CBOX_IOADDR, tmpstr, 19);
  637. if (tmpstr[0] == 'N') // Not Available (PCI)
  638. dev->IoAddress = 1;
  639. else
  640. {
  641. stat= sscanf(tmpstr,"%lx",&val);
  642. if ((stat == 1) && (val >= 2))
  643. {
  644. dev->IoAddress = val;
  645. }
  646. }
  647. break;
  648. }
  649. }
  650. /*----------------------------------------------------------
  651. set_io_addr_field -
  652. |------------------------------------------------------------*/
  653. static int set_io_addr_field(HWND hDlg, WORD id)
  654. {
  655. int io_pick, i, v;
  656. WORD lo;
  657. BOOL is_avail;
  658. static WORD hex_addresses[] = {0x100, 0x140, 0x180, 0x1c0,
  659. 0x200, 0x240, 0x280, 0x2c0,
  660. 0x300, 0x340, 0x380, 0x3c0, 0};
  661. HWND hwnd;
  662. char tmpstr[60];
  663. Device_Config *dev;
  664. dev = &wi->dev[glob_info->device_selected];
  665. //------------------ fill io-address
  666. hwnd = GetDlgItem(hDlg, IDC_CBOX_IOADDR);
  667. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  668. io_pick = 0;
  669. if (dev->IoAddress == 1) // pci
  670. {
  671. io_pick = 1;
  672. strcpy(tmpstr, "N/A");
  673. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM) tmpstr);
  674. SendMessage(hwnd, CB_SELECTSTRING, (WPARAM) -1, (LPARAM)(char far *) tmpstr);
  675. }
  676. else
  677. {
  678. for (i=0; hex_addresses[i] != 0; i++)
  679. {
  680. lo = hex_addresses[i];
  681. if (dev->IoAddress == lo)
  682. {
  683. io_pick = i;
  684. }
  685. // decide whether the current address is already in use or is available
  686. is_avail = TRUE; // assume true unless we find otherwise
  687. for (v = 0; v < wi->NumDevices; v++)
  688. {
  689. if ((wi->dev[v].IoAddress == lo) &&
  690. (v != glob_info->device_selected))
  691. {
  692. is_avail = FALSE;
  693. break;
  694. }
  695. }
  696. if (is_avail)
  697. {
  698. wsprintf(tmpstr,"%x Hex",lo);
  699. if (lo == 0x180)
  700. strcat(tmpstr," Default");
  701. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM) tmpstr);
  702. // if this was the user's choice from the wizard, highlight it
  703. if (lo == dev->IoAddress)
  704. SendMessage(hwnd, CB_SELECTSTRING, (WPARAM) -1, (LPARAM)(char far *) tmpstr);
  705. }
  706. }
  707. }
  708. // control whether the io base address combo box is enabled or disabled
  709. if (wi->dev[glob_info->device_selected].IoAddress == 1)
  710. EnableWindow(hwnd, 0);
  711. else
  712. EnableWindow(hwnd, 1);
  713. return 0;
  714. }
  715. #ifdef S_VS
  716. /*----------------------------------------------------------
  717. set_mac_field -
  718. |------------------------------------------------------------*/
  719. static int set_mac_field(HWND hDlg, WORD id)
  720. {
  721. HWND hwnd;
  722. char tmpstr[60];
  723. Device_Config *dev;
  724. int i;
  725. int addr_used, nbytes;
  726. BYTE *macbuf;
  727. BYTE *mac;
  728. dev = &wi->dev[glob_info->device_selected];
  729. //------------------ fill in mac addr selection
  730. hwnd = GetDlgItem(hDlg, id);
  731. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  732. // ping the devices to get mac list to display, also collect
  733. // info for device advisor
  734. macbuf = ping_devices(&glob_dstatus, &nbytes);
  735. if ((macbuf != NULL) && (nbytes != 0))
  736. {
  737. for (i=0; i<nbytes/8; i++)
  738. {
  739. mac = &macbuf[i*8];
  740. format_mac_addr(tmpstr, mac);
  741. if (mac[6] & FLAG_APPL_RUNNING)
  742. {
  743. if (mac[6] & FLAG_NOT_OWNER)
  744. {
  745. strcat(tmpstr, " (used)");
  746. }
  747. else
  748. {
  749. if (!mac_match(mac, dev->MacAddr))
  750. {
  751. // why are devices saying we are owner when our server is
  752. // not configured for them??? this must be a bug in box?
  753. strcat(tmpstr, " (Used)");
  754. }
  755. else strcat(tmpstr, " (ours)");
  756. }
  757. }
  758. else
  759. {
  760. // just leave it blank
  761. // strcat(tmpstr, " (free)");
  762. }
  763. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) tmpstr);
  764. }
  765. }
  766. addr_used = 1;
  767. if ( (mac_match(dev->MacAddr, broadcast_addr)) ||
  768. (mac_match(dev->MacAddr, mac_zero_addr)) )
  769. addr_used = 0;
  770. if (addr_used)
  771. {
  772. mac = &dev->MacAddr[0];
  773. format_mac_addr(tmpstr, mac);
  774. }
  775. else
  776. {
  777. memset(dev->MacAddr, 0, 6);
  778. strcpy(tmpstr, "00 C0 4E # # #");
  779. }
  780. // set the text in the window
  781. SetDlgItemText(hDlg, IDC_CBOX_MACADDR, tmpstr);
  782. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "00 C0 4E # # #");
  783. DbgPrintf(D_Level,(TEXT("END set_macfield\n")));
  784. return 0;
  785. }
  786. /*----------------------------------------------------------
  787. get_mac_field -
  788. |------------------------------------------------------------*/
  789. int get_mac_field(HWND hDlg, WORD id, BYTE *MacAddr)
  790. {
  791. int mac_nums[6];
  792. int stat,i;
  793. char tmpstr[64];
  794. Device_Config *dev;
  795. int bad;
  796. int ret_stat = 0;
  797. if (glob_info->device_selected >= wi->NumDevices)
  798. glob_info->device_selected = 0;
  799. dev = &wi->dev[glob_info->device_selected];
  800. bad = 0;
  801. GetDlgItemText(hDlg, id, tmpstr, 20);
  802. {
  803. stat = sscanf(tmpstr, "%x %x %x %x %x %x",
  804. &mac_nums[0], &mac_nums[1], &mac_nums[2],
  805. &mac_nums[3], &mac_nums[4], &mac_nums[5]);
  806. if (stat == 6)
  807. {
  808. for (i=0; i<6; i++)
  809. {
  810. if (mac_nums[0] > 0xff)
  811. bad = 1;
  812. }
  813. if (!bad)
  814. {
  815. MacAddr[0] = mac_nums[0];
  816. MacAddr[1] = mac_nums[1];
  817. MacAddr[2] = mac_nums[2];
  818. MacAddr[3] = mac_nums[3];
  819. MacAddr[4] = mac_nums[4];
  820. MacAddr[5] = mac_nums[5];
  821. if (mac_match(broadcast_addr, dev->MacAddr))
  822. {
  823. memset(dev->MacAddr,0,6); // all zeros = auto
  824. }
  825. }
  826. else
  827. bad = 1;
  828. }
  829. else
  830. bad = 1;
  831. } // not autodetect
  832. if (bad)
  833. {
  834. our_message(&wi->ip,RcStr((MSGSTR+1)),MB_OK);
  835. memset(MacAddr,0,6); // all zeros = auto
  836. ret_stat = 1;
  837. }
  838. return ret_stat;
  839. }
  840. #endif
  841. #ifdef S_RK
  842. /*---------------------------------------------------------------------------
  843. PaintRockers - Paints the Rocker Switches
  844. |---------------------------------------------------------------------------*/
  845. static int PaintRockers(HWND hWnd, int brd)
  846. {
  847. HDC hDC;
  848. //POINT2D pts[18];
  849. //POINT2D epts[6];
  850. //HBRUSH hbrush;
  851. RECT rect;
  852. int x,y,cx,cy, sw_i, top;
  853. int sw_size = 8;
  854. int sw_space = 2;
  855. //int num_hi = 2;
  856. int but_in;
  857. int sw_on[8];
  858. int i;
  859. //static HPEN hpens = NULL;
  860. //static HPEN hpenh = NULL;
  861. //static HBRUSH hbrushf = NULL;
  862. int base_x = 300;
  863. int base_y = 120;
  864. char tmpstr[40];
  865. int x_cell_size;
  866. int y_cell_size;
  867. int brd_index;
  868. int io_address;
  869. RECT spot, main; // left, top, right, bottom
  870. i = glob_info->device_selected;
  871. if (wi->dev[i].IoAddress < 0x100) // not isa board
  872. return 1; // err, no switches
  873. // figure out the rocker address
  874. brd_index = 0;
  875. io_address = 0;
  876. for (i=0; i<wi->NumDevices; i++)
  877. {
  878. if (wi->dev[i].IoAddress >= 0x100) // isa board
  879. {
  880. if (brd_index == 0)
  881. {
  882. io_address = wi->dev[i].IoAddress;
  883. }
  884. if (i == glob_info->device_selected)
  885. break;
  886. ++brd_index;
  887. }
  888. }
  889. io_address += (brd_index * 0x400); // example: 180H, 580H, ..
  890. hDC = GetDC(hWnd);
  891. // position to the left of the io-address field
  892. GetWindowRect(GetDlgItem(hWnd, IDC_CBOX_IOADDR), &spot);
  893. GetWindowRect(hWnd, &main);
  894. spot.right -= main.left;
  895. spot.top -= main.top;
  896. base_x = spot.right + 25;
  897. base_y = spot.top;
  898. x_cell_size = sw_size + sw_space;
  899. y_cell_size = sw_size + sw_space;
  900. // calculate which switch is on.
  901. io_address += 0x40; // go from 180 to 1c0(rockers set mudbac address)
  902. io_address >>= 6; // kill 40H worth(rocker sw1 starts at 40h)
  903. for (i=0; i<8; i++)
  904. {
  905. if (io_address & 1)
  906. sw_on[i] = 0;
  907. else sw_on[i] = 1;
  908. io_address >>= 1; // to next bit
  909. }
  910. // erase background and draw border of rockers
  911. x = base_x - (sw_space*3);
  912. y = base_y - ((sw_size + sw_space) * 2);
  913. cx = ((sw_size + sw_space) * 9);
  914. cy = ((sw_size + sw_space) * 6);
  915. draw_but(hDC, x,y,cx,cy, 2);
  916. // draw the rockers
  917. // top and left border, poly_border will calculate line endpts to draw
  918. SelectObject(hDC, GetStockObject(NULL_BRUSH));
  919. for (sw_i = 0; sw_i < 8; ++sw_i) // rocker switches
  920. {
  921. for (top = 0; top < 2; ++top) // top = 1 if at top of rocker
  922. {
  923. if (top)
  924. {
  925. // draw the switch(as a popped up button)
  926. but_in = 0;
  927. y = base_y;
  928. if (!sw_on[sw_i])
  929. y += ((sw_size + sw_space));
  930. cx = sw_size;
  931. cy = sw_size;
  932. }
  933. else
  934. {
  935. // draw the slot(as a pushed in button hole)
  936. but_in = 1;
  937. x = base_x + ((sw_size + sw_space) * sw_i);
  938. y = base_y + ((sw_size + sw_space) * top);
  939. cx = sw_size;
  940. cy = (sw_size * 2) + sw_space;
  941. }
  942. draw_but(hDC, x,y,cx,cy, but_in);
  943. } // top
  944. // draw the rocker switch number
  945. rect.left = x;
  946. rect.right = x + 6;
  947. rect.top = base_y + ((sw_size + sw_space) * 2);
  948. rect.bottom = rect.top + 14;
  949. SetBkMode(hDC,TRANSPARENT);
  950. SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
  951. wsprintf(tmpstr, "%d", sw_i+1);
  952. DrawText(hDC, tmpstr, strlen(tmpstr), &rect,
  953. DT_CENTER | DT_VCENTER | DT_WORDBREAK);
  954. } // sw_i
  955. // draw the "ON"
  956. rect.left = base_x;
  957. rect.right = base_x + 18;
  958. rect.top = base_y - (sw_size + sw_space) - 6;
  959. rect.bottom = rect.top + 14;
  960. SetBkMode(hDC,TRANSPARENT);
  961. SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
  962. DrawText(hDC, "ON", 2, &rect,
  963. DT_CENTER | DT_VCENTER | DT_WORDBREAK);
  964. ReleaseDC(hWnd, hDC);
  965. return 0;
  966. }
  967. /*----------------------------------------------------------
  968. draw_but - draw a button
  969. |------------------------------------------------------------*/
  970. static void draw_but(HDC hDC, int x, int y, int cx, int cy, int but_in)
  971. {
  972. static HPEN hpens = NULL;
  973. static HPEN hpenh = NULL;
  974. static HBRUSH hbrushf = NULL;
  975. POINT2D pts[18];
  976. POINT2D epts[6];
  977. int num_hi = 2; // number of highlight lines.
  978. epts[0].x = x;
  979. epts[0].y = y+cy;
  980. epts[1].x = x;
  981. epts[1].y = y;
  982. epts[2].x = x+cx;
  983. epts[2].y = y;
  984. epts[3].x = x+cx;
  985. epts[3].y = y+cy;
  986. // setup some pens to use
  987. if (hpens == NULL)
  988. {
  989. hpens = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
  990. hpenh = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHILIGHT));
  991. hbrushf = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  992. }
  993. if (but_in & 2) // fill background, black outline(special kludge case)
  994. {
  995. SelectObject(hDC, hbrushf);
  996. SelectObject(hDC, GetStockObject(BLACK_PEN));
  997. Polyline(hDC, (POINT *)&epts[0], 4);
  998. but_in &= 1;
  999. }
  1000. SelectObject(hDC, GetStockObject(NULL_BRUSH));
  1001. poly_border(pts, epts, num_hi); // calculate endpts
  1002. if (but_in)
  1003. SelectObject(hDC, GetStockObject(BLACK_PEN)); // pushed in look
  1004. else SelectObject(hDC, GetStockObject(WHITE_PEN));
  1005. Polyline(hDC, (POINT *)&pts[0], num_hi*3);
  1006. if (num_hi > 1)
  1007. { // draw the middle shade inbetween hilite lines
  1008. if (but_in)
  1009. SelectObject(hDC, hpens); // pushed in look, shadow on top
  1010. else SelectObject(hDC, hpenh); // hilite on top
  1011. Polyline(hDC, (POINT *)&pts[num_hi*3-3], 3);
  1012. }
  1013. // bottom and right border
  1014. SelectObject(hDC, GetStockObject(NULL_BRUSH));
  1015. epts[1].x = x+cx;
  1016. epts[1].y = y+cy;
  1017. poly_border(pts, epts, num_hi); // calc bottom line endpts
  1018. if (but_in)
  1019. SelectObject(hDC, GetStockObject(WHITE_PEN)); // pushed out look
  1020. else SelectObject(hDC, GetStockObject(BLACK_PEN));
  1021. Polyline(hDC, (POINT *)&pts[0], num_hi*3);
  1022. if (num_hi > 1)
  1023. {
  1024. if (but_in)
  1025. SelectObject(hDC, hpenh); // pushed out look
  1026. else SelectObject(hDC, hpens);
  1027. Polyline(hDC, (POINT *)&pts[num_hi*3-3], 3);
  1028. }
  1029. }
  1030. /*----------------------------------------------------------
  1031. poly_border - fill in pnts to shadow or highlight a button
  1032. using one polyline call.
  1033. ends[] - ctrl pnts, 3 for box(top & left) or (bottom & right)
  1034. |------------------------------------------------------------*/
  1035. static int poly_border(POINT2D *pts, POINT2D *ends, int lines)
  1036. {
  1037. int li;
  1038. int pi,j;
  1039. static POINT2D top[3] = {{1,-1}, {1,1}, {-1,1}};
  1040. static POINT2D bot[3] = {{1,-1}, {-1,-1}, {-1,1}};
  1041. POINT2D *adj;
  1042. if (ends[1].x == ends[0].x)
  1043. adj = top;
  1044. else adj = bot;
  1045. pi = 0;
  1046. li = 0;
  1047. while (li < lines)
  1048. {
  1049. for (j=0; j<3; j++)
  1050. {
  1051. pts[pi].x = ends[j].x + (li * adj[j].x);
  1052. pts[pi].y = ends[j].y + (li * adj[j].y);
  1053. ++pi;
  1054. }
  1055. if ((lines & 1) == 0) // odd
  1056. {
  1057. ++li;
  1058. for (j=2; j>=0; j--)
  1059. {
  1060. pts[pi].x = ends[j].x + (li * adj[j].x);
  1061. pts[pi].y = ends[j].y + (li * adj[j].y);
  1062. ++pi;
  1063. }
  1064. }
  1065. ++li;
  1066. }
  1067. return pi;
  1068. }
  1069. #endif
  1070. /*---------------------------------------------------------------------------
  1071. PaintIcon - Paints the Icon in the property sheet.
  1072. |---------------------------------------------------------------------------*/
  1073. static int PaintIcon(HWND hWnd)
  1074. {
  1075. // int status;
  1076. HBITMAP hBitMap;
  1077. HGDIOBJ hGdiObj;
  1078. HDC hDC, hMemDC ;
  1079. PAINTSTRUCT ps ;
  1080. RECT spot, main; // left, top, right, bottom
  1081. GetWindowRect(GetDlgItem(hWnd, IDB_HELP), &spot);
  1082. GetWindowRect(hWnd, &main);
  1083. #ifdef COMMENT_OUT
  1084. rect = &right;
  1085. mess("hlp r:%d l:%d b:%d t:%d",
  1086. rect->right, rect->left, rect->bottom, rect->top);
  1087. #endif
  1088. spot.left -= main.left;
  1089. spot.top -= main.top;
  1090. spot.left += 5;
  1091. spot.top += 20; // spacing
  1092. // load bitmap and display it
  1093. hDC = BeginPaint( hWnd, &ps ) ;
  1094. if (NULL != (hMemDC = CreateCompatibleDC( hDC )))
  1095. {
  1096. hBitMap = LoadBitmap(glob_hinst,
  1097. MAKEINTRESOURCE(BMP_SMALL_LOGO));
  1098. hGdiObj = SelectObject(hMemDC, hBitMap);
  1099. BitBlt( hDC, spot.left, spot.top, 100, 100, hMemDC, 0, 0, SRCCOPY ) ;
  1100. //StretchBlt( hDC, 5, 5, 600,100, hMemDC, 0, 0, 446, 85, SRCCOPY ) ;
  1101. DeleteObject( SelectObject( hMemDC, hGdiObj ) ) ;
  1102. DeleteDC( hMemDC ) ;
  1103. }
  1104. EndPaint( hWnd, &ps ) ;
  1105. return 0;
  1106. }
  1107. /*---------------------------------------------------------------------------
  1108. PaintLogo - Paints the logo bitmap in the device property sheet
  1109. |---------------------------------------------------------------------------*/
  1110. static int PaintLogo(HWND hWnd)
  1111. {
  1112. HBITMAP hBitMap;
  1113. HGDIOBJ hGdiObj;
  1114. HDC hDC, hMemDC;
  1115. PAINTSTRUCT ps;
  1116. BITMAP bm;
  1117. RECT r;
  1118. POINT pt;
  1119. // load bitmap and display it
  1120. hDC = BeginPaint( hWnd, &ps ) ;
  1121. GetClientRect(hWnd, &r);
  1122. if (NULL != (hMemDC = CreateCompatibleDC( hDC )))
  1123. {
  1124. #ifdef S_RK
  1125. if (wi->dev[glob_info->device_selected].ModemDevice == TYPE_RM_VS2000)
  1126. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_RKTMODEM_LOGO));
  1127. else if (wi->dev[glob_info->device_selected].ModemDevice == TYPE_RMII)
  1128. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_RKTMODEMII_LOGO));
  1129. else if (wi->dev[glob_info->device_selected].ModemDevice == TYPE_RM_i)
  1130. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_RKTMODEM_INTL_LOGO));
  1131. else
  1132. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_RKTPORT_LOGO));
  1133. #else
  1134. if (wi->dev[glob_info->device_selected].HubDevice == 1)
  1135. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_RKTHUB_LOGO));
  1136. else
  1137. hBitMap = LoadBitmap(glob_hinst, MAKEINTRESOURCE(BMP_VS_FULL_LOGO));
  1138. #endif
  1139. hGdiObj = SelectObject(hMemDC, hBitMap);
  1140. GetObject(hBitMap, sizeof(BITMAP), (PSTR) &bm);
  1141. pt.x = r.right - r.left + 1;
  1142. pt.y = r.bottom - r.top + 1;
  1143. StretchBlt( hDC, 0, 0, pt.x, pt.y, hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY );
  1144. DeleteObject( SelectObject( hMemDC, hGdiObj ) ) ;
  1145. DeleteDC( hMemDC ) ;
  1146. }
  1147. EndPaint( hWnd, &ps ) ;
  1148. return 0;
  1149. }
  1150. #ifdef S_VS
  1151. /*------------------------------------------------------------------------
  1152. StatusPropSheet -
  1153. dialogue window procedure for add-on device status sheet...
  1154. |------------------------------------------------------------------------*/
  1155. BOOL WINAPI
  1156. StatusPropSheet(
  1157. IN HWND hDlg,
  1158. IN UINT uMessage,
  1159. IN WPARAM wParam,
  1160. IN LPARAM lParam)
  1161. {
  1162. OUR_INFO *OurProps;
  1163. WORD uCmd;
  1164. OurProps = (OUR_INFO *)GetWindowLong(hDlg,DWL_USER);
  1165. switch (uMessage) {
  1166. case WM_INITDIALOG: {
  1167. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  1168. SetWindowLong(hDlg,DWL_USER,(LONG)OurProps);
  1169. return TRUE;
  1170. }
  1171. case WM_COMMAND: {
  1172. uCmd = HIWORD(wParam);
  1173. switch (LOWORD(wParam)) {
  1174. //check for reset button pushed...
  1175. case IDB_STAT_RESET: {
  1176. build_advisor_display(hDlg,&glob_dstatus,1);
  1177. return(TRUE);
  1178. }
  1179. //check for refresh button pushed...
  1180. case IDB_REFRESH: {
  1181. build_advisor_display(hDlg,&glob_dstatus,0);
  1182. return(TRUE);
  1183. }
  1184. }
  1185. return FALSE;
  1186. }
  1187. case WM_PAINT: {
  1188. PaintIcon(hDlg);
  1189. return FALSE;
  1190. }
  1191. case WM_HELP: {
  1192. our_context_help(lParam);
  1193. return FALSE;
  1194. }
  1195. case WM_NOTIFY : {
  1196. switch (((NMHDR *)lParam)->code){
  1197. case PSN_HELP : {
  1198. our_help(&wi->ip, IDD_STATUS);
  1199. break;
  1200. }
  1201. case PSN_SETACTIVE : {
  1202. build_advisor_display(hDlg,&glob_dstatus,0);
  1203. return TRUE;
  1204. }
  1205. default : {
  1206. return FALSE;
  1207. }
  1208. }
  1209. break;
  1210. }
  1211. default : {
  1212. return FALSE;
  1213. }
  1214. }
  1215. }
  1216. /*------------------------------------------------------------------------
  1217. build_advisor_display -
  1218. |------------------------------------------------------------------------*/
  1219. static void build_advisor_display(HWND hDlg,DSTATUS *pDstatus,int reset)
  1220. {
  1221. int nBytes;
  1222. int do_ping;
  1223. get_status(pDstatus,reset);
  1224. if ((pDstatus->vsl_device_status_found) &&
  1225. (pDstatus->calc_dev.state == VSL_STATE_ACTIVE))
  1226. {
  1227. // no need for ping, since our driver is not configured for
  1228. // the mac address we think it is, or our driver says it is
  1229. // running like a champ.
  1230. do_ping = 0;
  1231. }
  1232. else
  1233. {
  1234. // the device is inactive, so do ping, see if we can see it on
  1235. // network.
  1236. do_ping = 1;
  1237. }
  1238. if (do_ping)
  1239. {
  1240. // ping returns -1 if bad, 0 if MAC not found, 1 if found...
  1241. ping_devices(pDstatus, &nBytes);
  1242. }
  1243. set_status_field(hDlg,IDC_ST_PM_LOADS,pDstatus);
  1244. set_status_field(hDlg,IDC_ST_STATE,pDstatus);
  1245. set_status_field(hDlg,IDC_ST_NIC_DVC_NAME,pDstatus);
  1246. set_status_field(hDlg,IDC_ST_NIC_MAC,pDstatus);
  1247. set_status_field(hDlg,IDC_ST_NIC_PKT_SENT,pDstatus);
  1248. set_status_field(hDlg,IDC_ST_NIC_PKT_RCVD_OURS,pDstatus);
  1249. set_status_field(hDlg,IDC_ST_NIC_PKT_RCVD_NOT_OURS,pDstatus);
  1250. set_status_field(hDlg,IDC_ST_VSL_MAC,pDstatus);
  1251. set_status_field(hDlg,IDC_ST_VSL_DETECTED,pDstatus);
  1252. set_status_field(hDlg,IDC_ST_VSL_STATE,pDstatus);
  1253. set_status_field(hDlg,IDC_ST_VSL_IFRAMES_SENT,pDstatus);
  1254. set_status_field(hDlg,IDC_ST_VSL_IFRAMES_RCVD,pDstatus);
  1255. set_status_field(hDlg,IDC_ST_VSL_IFRAMES_RESENT,pDstatus);
  1256. set_status_field(hDlg,IDC_ST_VSL_IFRAMES_OUTOFSEQ,pDstatus);
  1257. }
  1258. /*------------------------------------------------------------------------
  1259. set_status_field -
  1260. |------------------------------------------------------------------------*/
  1261. static void
  1262. set_status_field(HWND hDlg,WORD id,DSTATUS *pDstatus)
  1263. {
  1264. char tmpstr[100];
  1265. Device_Config *vs;
  1266. unsigned int total;
  1267. PROBE_NIC_STRUCT *d_nic = &pDstatus->calc_nic;
  1268. PROBE_DEVICE_STRUCT *d_dev = &pDstatus->calc_dev;
  1269. tmpstr[0] = 0;
  1270. vs = &wi->dev[glob_info->device_selected];
  1271. switch(id) {
  1272. case IDC_EB_NAME:
  1273. SetDlgItemText(hDlg,id,vs->Name);
  1274. break;
  1275. case IDC_ST_STATE:
  1276. SetDlgItemText(
  1277. hDlg,
  1278. id,
  1279. (LPCTSTR)(AdvisoryString[pDstatus->verbose_advise_state]));
  1280. break;
  1281. case IDC_ST_NIC_DVC_NAME:
  1282. if (pDstatus->vsl_nic_status_found) // 1=driver found nic status.
  1283. strcpy(tmpstr,d_nic->NicName);
  1284. SetDlgItemText(hDlg,id,tmpstr);
  1285. break;
  1286. case IDC_ST_NIC_MAC:
  1287. if (pDstatus->vsl_nic_status_found) // 1=driver found nic status.
  1288. format_mac_addr(tmpstr, d_nic->address);
  1289. SetDlgItemText(hDlg,id,tmpstr);
  1290. break;
  1291. case IDC_ST_VSL_MAC:
  1292. format_mac_addr(tmpstr, vs->MacAddr);
  1293. SetDlgItemText(hDlg,id,tmpstr);
  1294. break;
  1295. case IDC_ST_VSL_DETECTED:
  1296. if (pDstatus->vsl_mac_list_found)
  1297. {
  1298. wsprintf(tmpstr,
  1299. "%d/%d",
  1300. pDstatus->vsl_detected,
  1301. pDstatus->vsl_available);
  1302. }
  1303. SetDlgItemText(hDlg,id,tmpstr);
  1304. break;
  1305. case IDC_ST_VSL_STATE:
  1306. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1307. {
  1308. if (d_dev->state < 5)
  1309. strcpy(tmpstr, vslink_state_table[d_dev->state]);
  1310. }
  1311. else
  1312. {
  1313. // indicate to the user that our mac-address has not been
  1314. // saved off and transferred to the driver
  1315. strcpy(tmpstr, "Not Configured");
  1316. }
  1317. SetDlgItemText(hDlg,id,tmpstr);
  1318. break;
  1319. case IDC_ST_VSL_IFRAMES_SENT:
  1320. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1321. {
  1322. //count = 0;
  1323. total = d_dev->iframes_sent;
  1324. total += d_dev->ctlframes_sent;
  1325. wsprintf(tmpstr,"%d",total);
  1326. }
  1327. SetDlgItemText(hDlg,id,tmpstr);
  1328. break;
  1329. case IDC_ST_VSL_IFRAMES_RESENT:
  1330. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1331. {
  1332. wsprintf(tmpstr,"%d",d_dev->iframes_resent);
  1333. }
  1334. SetDlgItemText(hDlg,id,tmpstr);
  1335. break;
  1336. case IDC_ST_VSL_IFRAMES_RCVD:
  1337. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1338. {
  1339. wsprintf(tmpstr,"%d",d_dev->frames_rcvd);
  1340. }
  1341. SetDlgItemText(hDlg,id,tmpstr);
  1342. break;
  1343. case IDC_ST_VSL_IFRAMES_OUTOFSEQ:
  1344. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1345. {
  1346. wsprintf(tmpstr,"%d",d_dev->iframes_outofseq);
  1347. }
  1348. SetDlgItemText(hDlg,id,tmpstr);
  1349. break;
  1350. case IDC_ST_NIC_PKT_SENT:
  1351. if (pDstatus->vsl_nic_status_found) // 1=driver found nic status.
  1352. wsprintf(tmpstr,"%d",d_nic->pkt_sent);
  1353. SetDlgItemText(hDlg,id,tmpstr);
  1354. break;
  1355. case IDC_ST_NIC_PKT_RCVD_OURS:
  1356. if (pDstatus->vsl_nic_status_found) // 1=driver found nic status.
  1357. wsprintf(tmpstr,"%d",d_nic->pkt_rcvd_ours);
  1358. SetDlgItemText(hDlg,id,tmpstr);
  1359. break;
  1360. case IDC_ST_NIC_PKT_RCVD_NOT_OURS:
  1361. if (pDstatus->vsl_nic_status_found) // 1=driver found nic status.
  1362. wsprintf(tmpstr,"%d",d_nic->pkt_rcvd_not_ours);
  1363. SetDlgItemText(hDlg,id,tmpstr);
  1364. break;
  1365. case IDC_ST_PM_LOADS:
  1366. tmpstr[0] = 0;
  1367. if (pDstatus->vsl_device_status_found) // 1=driver found matching VS config.
  1368. {
  1369. wsprintf(tmpstr, "%d/%d",
  1370. d_dev->good_loads,
  1371. d_dev->total_loads);
  1372. }
  1373. SetDlgItemText(hDlg,id,tmpstr);
  1374. break;
  1375. } // end of switch
  1376. } // end proc
  1377. #define IOCTL_STAT_BUFSIZE 500
  1378. /*------------------------------------------------------------------------
  1379. get_status - query the driver for device network statistics and
  1380. associated nic card network statistics. These stats are kept
  1381. as overflow/wrapping DWORD counters in driver, we do some math
  1382. on current and previous values read to determine calculated values.
  1383. |------------------------------------------------------------------------*/
  1384. static void get_status(DSTATUS *pDstatus,int reset)
  1385. {
  1386. Device_Config *vs;
  1387. PROBE_NIC_STRUCT *curr_nic = &pDstatus->curr_nic;
  1388. PROBE_NIC_STRUCT *prev_nic = &pDstatus->prev_nic;
  1389. PROBE_NIC_STRUCT *calc_nic = &pDstatus->calc_nic;
  1390. PROBE_NIC_STRUCT *temp_nic = &pDstatus->temp_nic;
  1391. PROBE_DEVICE_STRUCT *curr_dev = &pDstatus->curr_dev;
  1392. PROBE_DEVICE_STRUCT *prev_dev = &pDstatus->prev_dev;
  1393. PROBE_DEVICE_STRUCT *calc_dev = &pDstatus->calc_dev;
  1394. PROBE_DEVICE_STRUCT *temp_dev = &pDstatus->temp_dev;
  1395. int rc;
  1396. BYTE *pIoctlStatusBuf,
  1397. *pNicStatBuf;
  1398. IoctlSetup ioctl_setup;
  1399. int product_id;
  1400. DbgPrintf(D_Level,(TEXT("get_status\n")));
  1401. product_id = NT_VS1000;
  1402. vs = &wi->dev[glob_info->device_selected];
  1403. STATE_CHANGE(STATE_not_init);
  1404. //open path for ioctl to retrieve device status list. make sure path
  1405. //exists first...
  1406. memset(&ioctl_setup,0,sizeof(IoctlSetup));
  1407. rc = ioctl_open(&ioctl_setup,product_id);
  1408. if (rc != 0)
  1409. {
  1410. pDstatus->vsl_driver_found = 0; // 1=we can talk to driver, 0=driver not loaded
  1411. pDstatus->vsl_device_status_found = 0; // 1=driver found matching VS config.
  1412. pDstatus->vsl_nic_status_found = 0; // 1=driver found nic status.
  1413. DbgPrintf(D_Error,(TEXT("Err1A\n")));
  1414. //error. could not talk to driver. bail...
  1415. STATE_CHANGE(STATE_driver_not_avail);
  1416. return;
  1417. }
  1418. //alloc space for all NIC and VSlink status reports...
  1419. pIoctlStatusBuf = calloc(1,IOCTL_STAT_BUFSIZE);
  1420. memset(pIoctlStatusBuf,0,IOCTL_STAT_BUFSIZE);
  1421. pNicStatBuf = &pIoctlStatusBuf[sizeof(PortMonBase)];
  1422. // tell the driver which device we want to query by sending
  1423. // the mac-address as the id.
  1424. memcpy(pNicStatBuf,vs->MacAddr,sizeof(vs->MacAddr));
  1425. //see if we need to signal driver to reset statistics...
  1426. // no, don't reset the driver statistics!
  1427. pNicStatBuf[sizeof(vs->MacAddr)] = 0;
  1428. //pNicStatBuf[sizeof(vs->MacAddr)] = (reset) ? 1 : 0;
  1429. //adjust size of status buffer down by length of ioctl control block...
  1430. ioctl_setup.buf_size = IOCTL_STAT_BUFSIZE;
  1431. //store --> to status buffer into ioctl control block...
  1432. ioctl_setup.pm_base = (PortMonBase *) pIoctlStatusBuf;
  1433. ioctl_setup.pm_base->struct_type = IOCTL_DEVICESTAT;
  1434. ioctl_setup.pm_base->struct_size = IOCTL_STAT_BUFSIZE - sizeof(PortMonBase);
  1435. ioctl_setup.pm_base->num_structs = 0;
  1436. ioctl_setup.pm_base->var1 = 0;
  1437. // update prev_dev to curr_dev before getting new values
  1438. memcpy(prev_dev, curr_dev, sizeof(*prev_dev));
  1439. rc = ioctl_call(&ioctl_setup); // get device status
  1440. if (rc) {
  1441. pDstatus->vsl_device_status_found = 0; // 1=driver found matching VS config.
  1442. DbgPrintf(D_Test, ("probe, dev not found\n"))
  1443. ioctl_close(&ioctl_setup);
  1444. DbgPrintf(D_Error,(TEXT("Err1B\n")));
  1445. memset(calc_nic, 0, sizeof(curr_nic));
  1446. //STATE_CHANGE(STATE_driver_not_avail);
  1447. STATE_CHANGE(STATE_not_configured);
  1448. free(pIoctlStatusBuf);
  1449. return; // failed ioctl call
  1450. }
  1451. pDstatus->vsl_device_status_found = 1; // 1=driver found matching VS config.
  1452. DbgPrintf(D_Test, ("probe, dev found\n"))
  1453. // copy over our new device info
  1454. memcpy(curr_dev, pNicStatBuf, sizeof(*curr_dev));
  1455. if (curr_dev->struct_size != sizeof(*curr_dev))
  1456. {
  1457. DbgPrintf(D_Level, (TEXT("dev bad size:%d\n"), curr_dev->struct_size));
  1458. }
  1459. // save calculated values temporarily in temp_dev
  1460. memcpy(temp_dev, calc_dev, sizeof(*temp_dev));
  1461. // update calc_dev from curr_dev, just copy over
  1462. memcpy(calc_dev, curr_dev, sizeof(*calc_dev));
  1463. // use a current and previous reading to measure the advance, or
  1464. // calculated value which is put in calc value.
  1465. NORM_COUNTER(calc_dev->iframes_sent, curr_dev->iframes_sent,
  1466. prev_dev->iframes_sent, temp_dev->iframes_sent);
  1467. NORM_COUNTER(calc_dev->ctlframes_sent, curr_dev->ctlframes_sent,
  1468. prev_dev->ctlframes_sent, temp_dev->ctlframes_sent);
  1469. NORM_COUNTER(calc_dev->rawframes_sent, curr_dev->rawframes_sent,
  1470. prev_dev->rawframes_sent, temp_dev->rawframes_sent);
  1471. NORM_COUNTER(calc_dev->iframes_resent, curr_dev->iframes_resent,
  1472. prev_dev->iframes_resent, temp_dev->iframes_resent);
  1473. NORM_COUNTER(calc_dev->frames_rcvd, curr_dev->frames_rcvd,
  1474. prev_dev->frames_rcvd, temp_dev->frames_rcvd);
  1475. NORM_COUNTER(calc_dev->iframes_outofseq, curr_dev->iframes_outofseq,
  1476. prev_dev->iframes_outofseq, temp_dev->iframes_outofseq);
  1477. DbgPrintf(D_Level, (TEXT("iframes_sent - ca:%d cu:%d pr:%d te:%d\n"),
  1478. calc_dev->iframes_sent, curr_dev->iframes_sent,
  1479. prev_dev->iframes_sent, temp_dev->iframes_sent));
  1480. DbgPrintf(D_Level, (TEXT("iframes_sent - ca:%d cu:%d pr:%d te:%d\n"),
  1481. calc_dev->ctlframes_sent, curr_dev->ctlframes_sent,
  1482. prev_dev->ctlframes_sent, temp_dev->ctlframes_sent));
  1483. DbgPrintf(D_Level, (TEXT("frames_rcvd - ca:%d cu:%d pr:%d te:%d\n"),
  1484. calc_dev->frames_rcvd, curr_dev->frames_rcvd,
  1485. prev_dev->frames_rcvd, temp_dev->frames_rcvd));
  1486. if (curr_dev->nic_index != 0)
  1487. {
  1488. DbgPrintf(D_Level, (TEXT("nic index:%d\n"), curr_dev->nic_index));
  1489. }
  1490. // tell driver which nic card we want to probe info on
  1491. *((BYTE *)pNicStatBuf) = (BYTE) curr_dev->nic_index;
  1492. *((BYTE *)pNicStatBuf+1) = 0;
  1493. ioctl_setup.pm_base->struct_type = IOCTL_NICSTAT;
  1494. ioctl_setup.pm_base->struct_size = IOCTL_STAT_BUFSIZE - sizeof(PortMonBase);
  1495. ioctl_setup.pm_base->num_structs = 0;
  1496. // update prev_dev to curr_dev before calculation
  1497. memcpy(prev_nic, curr_nic, sizeof(*prev_nic));
  1498. rc = ioctl_call(&ioctl_setup); // get NIC and board status...
  1499. if (rc) {
  1500. pDstatus->vsl_nic_status_found = 0; // 1=driver found nic status.
  1501. ioctl_close(&ioctl_setup);
  1502. DbgPrintf(D_Error, (TEXT("nic not avail\n")));
  1503. STATE_CHANGE(STATE_nic_not_avail);
  1504. free(pIoctlStatusBuf);
  1505. return; // failed ioctl call
  1506. }
  1507. pDstatus->vsl_nic_status_found = 1; // 1=driver found nic status.
  1508. // copy over our new device info
  1509. memcpy(curr_nic, pNicStatBuf, sizeof(*curr_nic));
  1510. if (curr_nic->struct_size != sizeof(*curr_nic))
  1511. {
  1512. DbgPrintf(D_Error, (TEXT("nic bad size:%d\n"), curr_nic->struct_size));
  1513. }
  1514. // save calculated values temporarily in temp_nic
  1515. memcpy(temp_nic, calc_nic, sizeof(*temp_nic));
  1516. // update calc_nic from curr_dev
  1517. memcpy(calc_nic, curr_nic, sizeof(*calc_nic));
  1518. // use a current and previous reading to measure the advance, or
  1519. // calculated value which is put in calc value.
  1520. NORM_COUNTER(calc_nic->pkt_sent, curr_nic->pkt_sent,
  1521. prev_nic->pkt_sent, temp_nic->pkt_sent);
  1522. NORM_COUNTER(calc_nic->pkt_rcvd_ours, curr_nic->pkt_rcvd_ours,
  1523. prev_nic->pkt_rcvd_ours, temp_nic->pkt_rcvd_ours);
  1524. NORM_COUNTER(calc_nic->pkt_rcvd_not_ours, curr_nic->pkt_rcvd_not_ours,
  1525. prev_nic->pkt_rcvd_not_ours, temp_nic->pkt_rcvd_not_ours);
  1526. DbgPrintf(D_Level, (TEXT("pkt_sent - ca:%d cu:%d pr:%d te:%d\n"),
  1527. calc_nic->pkt_sent, curr_nic->pkt_sent,
  1528. prev_nic->pkt_sent, temp_nic->pkt_sent));
  1529. DbgPrintf(D_Level, (TEXT("pkt_rcvd_ours - ca:%d cu:%d pr:%d te:%d\n"),
  1530. calc_nic->pkt_rcvd_ours, curr_nic->pkt_rcvd_ours,
  1531. prev_nic->pkt_rcvd_ours, temp_nic->pkt_rcvd_ours));
  1532. DbgPrintf(D_Level, (TEXT("pkt_rcvd_not_ours - ca:%d cu:%d pr:%d te:%d\n"),
  1533. calc_nic->pkt_rcvd_not_ours, curr_nic->pkt_rcvd_not_ours,
  1534. prev_nic->pkt_rcvd_not_ours, temp_nic->pkt_rcvd_not_ours));
  1535. if (reset) {
  1536. DbgPrintf(D_Level, (TEXT("Reset NicStats\n")));
  1537. calc_dev->iframes_sent = 0;
  1538. calc_dev->ctlframes_sent = 0;
  1539. calc_dev->rawframes_sent = 0;
  1540. calc_dev->iframes_resent = 0;
  1541. calc_dev->frames_rcvd = 0;
  1542. calc_dev->iframes_outofseq = 0;
  1543. calc_nic->pkt_sent = 0;
  1544. calc_nic->pkt_rcvd_ours = 0;
  1545. calc_nic->pkt_rcvd_not_ours = 0;
  1546. ioctl_close(&ioctl_setup);
  1547. STATE_CHANGE(STATE_reset);
  1548. free(pIoctlStatusBuf);
  1549. return;
  1550. }
  1551. //check state of NIC card...
  1552. if (!pDstatus->curr_nic.Open)
  1553. {
  1554. ioctl_close(&ioctl_setup);
  1555. DbgPrintf(D_Level, (TEXT("Nic Not Open\n")));
  1556. memset(calc_nic, 0, sizeof(curr_nic));
  1557. STATE_CHANGE(STATE_nic_not_avail);
  1558. //STATE_CHANGE(STATE_network_not_avail);
  1559. free(pIoctlStatusBuf);
  1560. return;
  1561. }
  1562. switch (curr_dev->state)
  1563. {
  1564. case VSL_STATE_INIT:
  1565. if (pDstatus->vsl_detected) // if some devices found in ping mac list
  1566. {
  1567. if (pDstatus->vsl_ping_device_found) // if our mac found in pinged list
  1568. {
  1569. if ((pDstatus->vsl_load_status & FLAG_NOT_OWNER) == FLAG_NOT_OWNER) {
  1570. STATE_CHANGE(STATE_not_owner);
  1571. }
  1572. else if ((pDstatus->vsl_load_status & FLAG_APPL_RUNNING) == 0) {
  1573. STATE_CHANGE(STATE_vslink_not_ready);
  1574. }
  1575. }
  1576. else // not found in list
  1577. {
  1578. STATE_CHANGE(STATE_vslink_not_avail);
  1579. }
  1580. }
  1581. else // none found in ping
  1582. {
  1583. STATE_CHANGE(STATE_no_vslinks_avail);
  1584. }
  1585. break;
  1586. case VSL_STATE_ACTIVE:
  1587. STATE_CHANGE(STATE_ok_no_traffic);
  1588. check_traffic_activity(pDstatus);
  1589. break; // end of state_active
  1590. case VSL_STATE_INITOWN:
  1591. case VSL_STATE_SENDCODE:
  1592. case VSL_STATE_CONNECT:
  1593. default:
  1594. STATE_CHANGE(STATE_vslink_not_ready);
  1595. break;
  1596. } // end of switch on state
  1597. ioctl_close(&ioctl_setup);
  1598. free(pIoctlStatusBuf);
  1599. DbgPrintf(D_Level, (TEXT("get_status done\n")));
  1600. return;
  1601. }
  1602. /*------------------------------------------------------------------------
  1603. check_traffic_activity -
  1604. check activity on NIC, network, & VS-Link device...
  1605. |------------------------------------------------------------------------*/
  1606. static void check_traffic_activity(DSTATUS *pDstatus)
  1607. {
  1608. PROBE_NIC_STRUCT *curr_nic = &pDstatus->curr_nic;
  1609. PROBE_NIC_STRUCT *prev_nic = &pDstatus->prev_nic;
  1610. PROBE_NIC_STRUCT *calc_nic = &pDstatus->calc_nic;
  1611. PROBE_DEVICE_STRUCT *curr_dev = &pDstatus->curr_dev;
  1612. PROBE_DEVICE_STRUCT *prev_dev = &pDstatus->prev_dev;
  1613. PROBE_DEVICE_STRUCT *calc_dev = &pDstatus->calc_dev;
  1614. ULONG percent_dropped;
  1615. // don't divide by zero
  1616. if ((curr_dev->iframes_outofseq + curr_dev->frames_rcvd) > 0)
  1617. percent_dropped = ((curr_dev->iframes_outofseq * 100) /
  1618. (curr_dev->iframes_outofseq + curr_dev->frames_rcvd) > 2);
  1619. else
  1620. percent_dropped = 0;
  1621. /*
  1622. iframes_sent are hdlc protocol data packets;
  1623. ctlframes_sent are hdlc protocol control packets;
  1624. rawframes_sent are write remote, read trace query, go, and upload
  1625. binary command packets;
  1626. iframes_resent are data packets retransmitted.
  1627. iframes_outofseq are data packets received out of order.
  1628. */
  1629. DbgPrintf(D_Level, (TEXT("Check Traffic\n")));
  1630. if ((curr_dev->iframes_sent + curr_dev->ctlframes_sent) ==
  1631. (prev_dev->iframes_sent + prev_dev->ctlframes_sent)) {
  1632. // no sent packets to the higher levels in the VS-Link recently...
  1633. STATE_CHANGE(STATE_ok_no_traffic);
  1634. // no send traffic - see if we've any recent receive traffic for
  1635. // delivery to higher levels...
  1636. if (curr_dev->frames_rcvd == prev_dev->frames_rcvd)
  1637. STATE_CHANGE(STATE_ok_no_traffic);
  1638. }
  1639. else if (curr_dev->frames_rcvd == prev_dev->frames_rcvd) {
  1640. // we've recently received any VS-Link packets for delivery to higher levels...
  1641. STATE_CHANGE(STATE_ok_no_traffic);
  1642. }
  1643. else {
  1644. //connection appears ok so far. dig in deeper...
  1645. STATE_CHANGE(STATE_ok);
  1646. }
  1647. DbgPrintf(D_Level, (TEXT("Check Traffic 2\n")));
  1648. //evaluate link integrity. see if we're retransmitting packets to this
  1649. //VS-Link...
  1650. if (curr_dev->iframes_resent != prev_dev->iframes_resent) {
  1651. STATE_CHANGE(STATE_poor_link);
  1652. }
  1653. else if ((curr_nic->pkt_rcvd_not_ours != prev_nic->pkt_rcvd_not_ours) &&
  1654. (curr_nic->pkt_rcvd_ours == prev_nic->pkt_rcvd_ours)) {
  1655. // all we're getting are packets that we're passing onto some
  1656. //other driver. we should be getting responses from the VS-Links...
  1657. STATE_CHANGE(STATE_poor_link);
  1658. }
  1659. else if (curr_dev->iframes_outofseq != prev_dev->iframes_outofseq) {
  1660. // we've received VS-Link packets out-of-sequence since last click...
  1661. STATE_CHANGE(STATE_poor_link);
  1662. }
  1663. else if ((curr_dev->iframes_outofseq) &&
  1664. (percent_dropped > 0)) {
  1665. // received 2% or more of VS-Link packets out-of-sequence (value per BF)...
  1666. STATE_CHANGE(STATE_poor_link);
  1667. }
  1668. DbgPrintf(D_Level, (TEXT("Check Traffic Done\n")));
  1669. }
  1670. /*------------------------------------------------------------------------
  1671. ping_devices -
  1672. ping for all active VS-Link devices, collect info for device advisor.
  1673. Return NULL or to list of mac-addresses.
  1674. |------------------------------------------------------------------------*/
  1675. static BYTE *ping_devices(DSTATUS *pDstatus, int *nBytes)
  1676. {
  1677. Device_Config *vs;
  1678. int rc,
  1679. nbytes;
  1680. BYTE *MacBuf;
  1681. int product_id;
  1682. int index;
  1683. DRIVER_MAC_STATUS *pMacStatus;
  1684. product_id = NT_VS1000;
  1685. pDstatus->vsl_ping_device_found = 0;
  1686. DbgPrintf(D_Level, (TEXT("Ping Devices\n")));
  1687. vs = &wi->dev[glob_info->device_selected];
  1688. MacBuf = our_get_ping_list(&rc, &nbytes);
  1689. pMacStatus = (DRIVER_MAC_STATUS *) MacBuf;
  1690. if (rc) {
  1691. nbytes = 0;
  1692. *nBytes = 0;
  1693. pDstatus->vsl_mac_list_found = 0;
  1694. DbgPrintf(D_Error, (TEXT("Err Mac List1\n")));
  1695. return NULL; // failed ioctl call
  1696. }
  1697. //are there any VS-Link MAC addresses out on the network?...
  1698. pDstatus->vsl_available = 0;
  1699. pDstatus->vsl_load_status = 0;
  1700. pDstatus->vsl_detected = (nbytes / sizeof(DRIVER_MAC_STATUS));
  1701. pDstatus->vsl_mac_list_found = 1;
  1702. rc = 0;
  1703. if ((nbytes / sizeof(DRIVER_MAC_STATUS)) == 0) {
  1704. DbgPrintf(D_Level, (TEXT("Zero Mac List\n")));
  1705. *nBytes = 0;
  1706. return NULL; // failed ioctl call
  1707. }
  1708. *nBytes = nbytes; // return number of bytes of mac list read
  1709. // ok; is our target one of them?...
  1710. for (index = 0;
  1711. index < (nbytes / (int)sizeof(DRIVER_MAC_STATUS));
  1712. index++)
  1713. {
  1714. // generate count of available VS-Links for loading at this time...
  1715. if ( ((pMacStatus->flags & FLAG_APPL_RUNNING) == 0) ||
  1716. (pMacStatus->flags & FLAG_OWNER_TIMEOUT) )
  1717. ++pDstatus->vsl_available;
  1718. //target MAC matches?...
  1719. if (mac_match(pMacStatus->mac,vs->MacAddr))
  1720. {
  1721. //ok; save its load status...
  1722. pDstatus->vsl_load_status = pMacStatus->flags;
  1723. pDstatus->vsl_ping_device_found = 1;
  1724. rc = 1;
  1725. }
  1726. ++pMacStatus;
  1727. } // end of for loop
  1728. return MacBuf;
  1729. }
  1730. #endif
  1731. /*------------------------------------------------------------------------
  1732. format_mac_addr -
  1733. |------------------------------------------------------------------------*/
  1734. void format_mac_addr(char *outstr, unsigned char *address)
  1735. {
  1736. wsprintf(outstr,
  1737. "%02X %02X %02X %02X %02X %02X",
  1738. address[0],
  1739. address[1],
  1740. address[2],
  1741. address[3],
  1742. address[4],
  1743. address[5]);
  1744. }