#include <stdio.h>
void listDevices (void)
{
int i;
char name[100];
int channel_count = 0;
unsigned int channel_on_card = 0;
printf("First argument must be a channel!\n\n");
printf("Channel\t Name\n");
printf("--------------------------------------------------------\n");
for (i = 0; (stat ==
canOK) && (i < channel_count); i++) {
name[0] = '\0';
printf("canGetChannelData(canCHANNELDATA_DEVDESCR_ASCII) failed.\n");
continue;
}
printf("canGetChannelData(canCHANNELDATA_CHAN_NO_ON_CARD) failed.\n");
continue;
}
printf("%d\t %s (Channel %u)\n", i, name, channel_on_card);
}
}
int isPasswordFree (unsigned int channelNumber)
{
printf("Failed to open configuration with empty password on channel %u\n", channelNumber);
return 0;
} else {
return 1;
}
}
int waitForDevice(unsigned int ean_hi, unsigned int ean_lo, unsigned int serial,
int timeout_in_ms)
{
unsigned long time_start;
printf("\nWaiting for device with EAN %08x%08x, and serial %u\n", ean_hi, ean_lo, serial);
time_start = GetTickCount();
Sleep(2000);
do {
int channel_count;
DWORD tmp_serial[2];
unsigned long tmp_ean[2];
int channel;
printf("canGetNumberOfChannels() failed.\n");
return -1;
}
for (channel=0; channel<channel_count; channel++) {
printf("canGetChannelData(canCHANNELDATA_CARD_UPC_NO) failed.\n");
return -2;
}
printf("canGetChannelData(canCHANNELDATA_CARD_SERIAL_NO) failed.\n");
return -3;
}
if (ean_hi == tmp_ean[1] && ean_lo == tmp_ean[0] && serial == tmp_serial[0]) {
printf("Found!\n\n");
return 0;
}
}
printf("Try again...\n");
Sleep(500);
} while (GetTickCount() < (time_start + timeout_in_ms));
printf("Device did not appear within given timeout\n\n");
return -4;
}
int isAvailibleForConfig (unsigned int canlib_channel, const char *password)
{
DWORD bus_type;
DWORD serial[2];
DWORD tmp_serial[2];
unsigned long ean[2];
unsigned long tmp_ean[2];
int chan_no;
int tmp_chan;
if (hnd < 0) {
printf("Channel %u can not be opened exclusively.\n", canlib_channel);
return 0;
}
if (stat) {
printf("ERROR: failed to get bustype %d\n", stat);
return 0;
}
printf("Channel is not local (bus type:%lu).\n", bus_type);
return 0;
}
tmp_chan = canlib_channel - chan_no;
while (1) {
if (hnd < 0) {
printf("Channel %d (same device as channel %u) can not be opened exclusively.\n", tmp_chan, canlib_channel);
return 0;
}
tmp_chan++;
if (tmp_ean[0] != ean[0] || tmp_ean[1] != ean[1] ||
tmp_serial[0] != serial[0] || tmp_serial[1] != serial[1]) {
break;
}
}
if (isPasswordFree(canlib_channel)) {
printf("No password is needed for configuring channel %u\n", canlib_channel);
printf("Failed to open configuration with empty password on channel %u\n", canlib_channel);
return 0;
} else {
return 0 == waitForDevice(ean[1], ean[0], serial[0], 10000);
}
} else {
printf("Password is needed for configuring channel %u\n", canlib_channel);
printf("Failed to open configuration with supplied password '%s' on channel %u\n", password, canlib_channel);
return 0;
} else {
return 0 == waitForDevice(ean[1], ean[0], serial[0], 10000);
}
}
return 1;
}
{
int32_t active = 0;
char ssid[40];
char securityString[200];
int32_t rssi;
int32_t channel;
uint32_t capability;
uint32_t type_wpa;
printf("Could not start scan (%d)\n", status);
return status;
}
do {
ssid, &capability, &type_wpa,
&wpa_info, &rsn_info );
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
printf("SSID: %s\n", ssid);
printf("RSSI: %d dBm\n", rssi);
printf("WLAN Channel: %d\n", channel);
printf("MAC address: %02X %02X %02X %02X %02X %02X\n",
printf("BSS type: %d\n", bss_type);
printf("Capabilities: 0x%04x\n", capability);
capability, type_wpa, &wpa_info, &rsn_info);
printf("Security");
printf("(truncated)");
}
printf(": %s\n", securityString);
}
}
{
char new_xml_config[4096];
char old_xml_config[4096];
char xml_error[2048];
status =
kvrConfigGet(handle, old_xml_config,
sizeof(old_xml_config));
printf("Could not read configuration from device (%d)\n", status);
return status;
}
printf("Old configuration: %s\n", old_xml_config);
memcpy(new_xml_config, old_xml_config, sizeof(old_xml_config));
memset(xml_error, 0, sizeof(xml_error));
printf("The XML configuration is not valid (%d):\n%s\n",
status, xml_error);
return status;
}
printf("Could not write configuration to device (%d)\n", status);
return status;
}
return status;
}
{
int32_t dhcp;
int32_t state;
int32_t tx_rate;
int32_t rx_rate;
int32_t channel;
int32_t rssi_mean;
int32_t tx_power;
int rtt_actual;
int rssi_actual;
printf("Could not start ping(%d)\n", status);
return status;
}
do {
Sleep(1000);
rtt, rtt_len, &rtt_actual);
printf("Could not get RSSI / RTT (%d)\n", status);
break;
}
&channel, &rssi_mean, &tx_power);
printf("Could not get status (%d)\n", status);
break;
}
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
printf("Connection state: %d\n", state);
printf("Transmit rate: %d kbit/s\n", tx_rate);
printf("Receive rate: %d kbit/s\n", rx_rate);
printf("Channel: %d\n", channel);
printf("Receive Signal Strength Indicator: %d dBm\n", rssi_mean);
printf("Transmit power level: %d dB\n", tx_power);
} while (--seconds > 0);
printf("Could not stop ping(%d)\n", status);
return status;
}
printf("Could not get IP info(%d)\n", status);
return status;
}
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
printf("DHCP: %s\n", dhcp ? "ON" : "OFF");
printf("MAC address: %02X %02X %02X %02X %02X %02X\n",
printf(
"IP Address: %d.%d.%d.%d\n", address.
address[0], address.
address[1],
printf(
"Netmask: %d.%d.%d.%d\n", netmask.
address[0], netmask.
address[1],
printf(
"Gateway: %d.%d.%d.%d\n", gateway.
address[0], gateway.
address[1],
return status;
}
int main (int argc, char *argv[])
{
char *password = "";
int canlib_channel;
DWORD serial[2];
unsigned long ean[2];
switch (argc) {
case 1:
listDevices();
return 0;
case 2:
canlib_channel = argv[1][0] - '0';
break;
default:
listDevices();
return -1;
}
if (isAvailibleForConfig (canlib_channel, password)) {
printf("Channel %d is availible for configuration\n", canlib_channel);
} else {
printf("Channel %d can not be opened for configuration.\n", canlib_channel);
return -1;
}
printf("Could not start config (%d)\n", status);
return status;
}
status = doScanNetworks(handle);
printf("Scan networks failed (%d)\n", status);
return status;
}
printf("Could not start config (%d)\n", status);
return status;
}
status = doConfigure(handle);
printf("Could not write new configuration (%d)\n", status);
return status;
}
if (waitForDevice(ean[1], ean[0], serial[0], 10000) != 0) {
printf("waitForDevice() failed.\n");
return -1;
}
printf("Could not start config (%d)\n", status);
return status;
}
status = doTryConfiguration(handle, 5);
printf("doTryConfiguration failed (%d)\n", status);
return status;
}
printf("\nDone!\n");
return 0;
}