📄 cardif_freebsd.c
字号:
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "set_ccmp_key not implemented.\n");
return -1;
}
/**********************************************************
*
* Delete a key
*
**********************************************************/
int cardif_delete_key(struct interface_data *intdata, int key_idx, int set_tx)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "delete_key not implemented.\n");
return -1;
}
/******************************************
*
* If our association timer expires, we need to attempt to associate again.
*
******************************************/
void cardif_association_timeout_expired(struct interface_data *intdata)
{
// And try to associate again.
cardif_associate(intdata, intdata->cur_essid);
}
/******************************************
*
* Do whatever we need to do in order to associate based on the flags in
* the ssids_list struct.
*
******************************************/
void cardif_associate(struct interface_data *intdata, char *newssid)
{
if (intdata == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid interface struct passed to %s!\n",
__FUNCTION__);
return;
}
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return;
}
/******************************************
*
* Ask the wireless card for the ESSID that we are currently connected to. If
* this is not a wireless card, or the information is not available, we should
* return an error.
*
******************************************/
int cardif_GetSSID(struct interface_data *thisint, char *ssid_name)
{
if (wireless == NULL)
{
debug_printf(DEBUG_NORMAL, "No valid call to get SSID for this driver!"
"\n");
return -1;
}
if ((thisint == NULL) || (ssid_name == NULL))
{
debug_printf(DEBUG_INT, "NULL value passed to %s!\n", __FUNCTION__);
return -1;
}
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/******************************************
*
* Get the Broadcast SSID (MAC address) of the Access Point we are connected
* to. If this is not a wireless card, or the information is not available,
* we should return an error.
*
******************************************/
int cardif_GetBSSID(struct interface_data *thisint, char *bssid_dest)
{
if (wireless == NULL) return -1;
if (thisint == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid interface data structure passed to %s!\n", __FUNCTION__);
return -1;
}
if (bssid_dest == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid bssid_dest in %s!\n", __FUNCTION__);
return -1;
}
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/******************************************
*
* Set the flag in the state machine that indicates if this interface is up
* or down. If there isn't an interface, we should return an error.
*
******************************************/
int cardif_get_if_state(struct interface_data *thisint)
{
int flags;
if (!_getiff(thisint->intName, &flags))
return XENONE;
return (flags & IFF_UP) != 0;
}
/******************************************
*
* Send a frame out of the network card interface. If there isn't an
* interface, we should return an error. We should return a different error
* if we have a problem sending the frame.
*
******************************************/
int cardif_sendframe(struct interface_data *thisint)
{
char nomac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int retval;
struct fbsd_sock_data *sockData;
struct config_network *network_data;
sockData= (struct fbsd_sock_data *) thisint->sockData;
if (thisint == NULL) return XEMALLOC;
if (thisint->send_size == 0) return XENONE;
network_data = config_get_network_config();
if (network_data == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid network configuration structure! "
"(%s:%d)\n", __FUNCTION__, __LINE__);
return XEBADCONFIG;
}
// The frame we are handed in shouldn't have a src/dest, so put it in.
memcpy(&thisint->sendframe[0], &thisint->dest_mac[0], 6);
memcpy(&thisint->sendframe[6], &thisint->source_mac[0], 6);
if (memcmp(nomac, (char *)&network_data->dest_mac[0], 6) != 0)
{
debug_printf(DEBUG_INT, "Static MAC address defined! Using it!\n");
memcpy(&thisint->sendframe[0], &network_data->dest_mac[0], 6);
}
debug_printf(DEBUG_EVERYTHING, "Frame to be sent : \n");
debug_hex_dump(DEBUG_EVERYTHING, thisint->sendframe, thisint->send_size);
snmp_dot1xSuppEapolFramesTx();
retval = write(sockData->bpf, thisint->sendframe, thisint->send_size);
if (retval != thisint->send_size)
debug_printf(DEBUG_NORMAL, "Couldn't send frame! %d: %s\n", errno, strerror(errno));
thisint->send_size = 0;
return retval;
}
/******************************************
*
* Get a frame from the network. Make sure to check the frame, to determine
* if it is something we care about, and act accordingly.
*
******************************************/
int cardif_getframe(struct interface_data *thisint)
{
int newsize=0;
char dot1x_default_dest[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
struct fbsd_sock_data *sockData;
uint8_t resultframe[1520];
int resultsize;
if (!cardif_frameavail(thisint))
return XENOFRAMES;
sockData= (struct fbsd_sock_data *) thisint->sockData;
struct bpf_hdr *bh = (struct bpf_hdr*) sockData->buf;
errno = 0;
resultsize = 1550;
newsize = read(sockData->bpf, sockData->buf, sockData->buf_size);
if (newsize > 0) {
debug_printf(DEBUG_EVERYTHING, "recvframe; %d (need to strip bpf header)\n", newsize);
if (bh->bh_datalen > resultsize) {
debug_printf(DEBUG_NORMAL, "Got a too big frame: %d?!\n", bh->bh_datalen);
return XENOFRAMES;
}
memcpy(resultframe, sockData->buf+bh->bh_hdrlen, bh->bh_datalen);
newsize = bh->bh_datalen;
}
if (newsize <= 0)
{
if (errno != EAGAIN)
{
debug_printf(DEBUG_NORMAL, "Error (%d) : %s (%s:%d)\n", errno,
strerror(errno), __FUNCTION__, __LINE__);
}
return XENOFRAMES;
} else {
debug_printf(DEBUG_EVERYTHING, "Got Frame : \n");
debug_hex_dump(DEBUG_EVERYTHING, resultframe, newsize);
}
snmp_dot1xSuppEapolFramesRx();
// Make sure that the frame we got is for us..
if ((memcmp(&thisint->source_mac[0], &resultframe[0], 6) == 0) ||
((memcmp(&resultframe[0], &dot1x_default_dest[0], 6) == 0) &&
(memcmp(&resultframe[6], &thisint->source_mac[0], 6) != 0)))
{
// Since we now know this frame is for us, record the address it
// came from.
snmp_dot1xSuppLastEapolFrameSource((char *)&resultframe[6]);
resultsize = newsize;
switch (config_get_destination())
{
case DEST_AUTO:
case DEST_SOURCE:
if (memcmp(thisint->dest_mac, &resultframe[6], 6) != 0)
{
debug_printf(DEBUG_INT, "Changing destination mac to source.\n");
}
memcpy(thisint->dest_mac, &resultframe[6], 6);
break;
case DEST_MULTICAST:
memcpy(thisint->dest_mac, dot1x_default_dest, 6);
break;
case DEST_BSSID:
cardif_GetBSSID(thisint, thisint->dest_mac);
break;
default:
debug_printf(DEBUG_NORMAL, "Unknown destination mode!\n");
break;
}
thisint->recv_size = newsize;
memcpy(thisint->recvframe, resultframe, newsize);
return newsize;
}
// Otherwise it isn't for us.
debug_printf(DEBUG_INT, "Got a frame, not for us.\n");
return XENOFRAMES;
}
/**************************************************************
*
* Set the state needed to associate to a WPA enabled AP, and actually
* do a WPA authentication.
*
**************************************************************/
int cardif_enable_wpa_state(struct interface_data *thisint)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/**************************************************************
*
* Clear the state needed to associate to a WPA enabled AP, and actually
* do a WPA authentication.
*
**************************************************************/
int cardif_disable_wpa_state(struct interface_data *thisint)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/**************************************************************
*
* Enable WPA (if it is supported.)
*
**************************************************************/
int cardif_enable_wpa(struct interface_data *thisint)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/**************************************************************
*
* Call this when we roam to a different AP, or disassociate from an AP.
*
**************************************************************/
int cardif_roam(struct interface_data *thisint)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/******************************************
*
* Return true if there is a frame in the queue to be processed.
*
******************************************/
int cardif_frameavail(struct interface_data *thisint)
{
fd_set readfds;
struct timeval timeout;
struct fbsd_sock_data *sockData;
int nfds, ready_sockets, result;
sockData= (struct fbsd_sock_data *) thisint->sockData;
FD_ZERO(&readfds);
FD_SET(sockData->bpf, &readfds);
timeout.tv_sec= timeout.tv_usec= 0; /* Non blocking. */
nfds= sockData->bpf+1;
do
{
ready_sockets= select(nfds, &readfds, (fd_set *) NULL,
(fd_set *) NULL, &timeout);
} while (ready_sockets<0 && errno==EINTR);
if (ready_sockets<0 && errno!=EINTR)
{
debug_printf(DEBUG_NORMAL, "Error reading sockets: %s\n", strerror(errno));
return FALSE;
}
result= ((ready_sockets>0 && FD_ISSET(sockData->bpf, &readfds)) ? TRUE : FALSE);
return result;
}
/******************************************
*
* Validate an interface, based on if it has a MAC address.
*
******************************************/
int cardif_validate(char *interface)
{
char mac[6];
if (_getmac(mac, interface) == XENONE)
return TRUE;
else
return FALSE;
}
/******************************************
*
* (en)/(dis)able countermeasures on this interface.
*
******************************************/
int cardif_countermeasures(struct interface_data *intdata, char endis)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/******************************************
*
* (en)/(dis)able receiving of unencrypted frames on this interface.
*
******************************************/
int cardif_drop_unencrypted(struct interface_data *intdata, char endis)
{
if (wireless == NULL) return -1;
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/*******************************************************
*
* Check to see if an interface is wireless. On freebsd, we look in
* /proc/net/wireless to see if the interface is registered with the
* wireless extensions.
*
*******************************************************/
int cardif_int_is_wireless(char *interface)
{
debug_printf(DEBUG_INT, "cardif_int_is_wireless not implemented, " \
"assuming %s is NOT wireless\n", interface);
return FALSE;
}
int cardif_get_wpa_ie(struct interface_data *intdata, char *iedata, int *ielen)
{
if (intdata == NULL)
{
debug_printf(DEBUG_NORMAL, "Error! Invalid interface data structure! "
"(%s:%d)\n", __FUNCTION__, __LINE__);
return XEMALLOC;
}
if (iedata == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid bucket for IE data! (%s:%d)\n",
__FUNCTION__, __LINE__);
return XEMALLOC;
}
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
int cardif_get_wpa2_ie(struct interface_data *intdata, char *iedata, int *ielen)
{
if (intdata == NULL)
{
debug_printf(DEBUG_NORMAL, "Error! Invalid interface data structure! "
"(%s:%d)\n", __FUNCTION__, __LINE__);
return XEMALLOC;
}
if (iedata == NULL)
{
debug_printf(DEBUG_NORMAL, "Invalid bucket for IE data! (%s:%d)\n",
__FUNCTION__, __LINE__);
return XEMALLOC;
}
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
/**************************************************************
*
* This function should clear out all keys that have been applied to the card.
* It should be indepentant of the type (WEP/TKIP/CCMP) of key that was
* applied.
*
**************************************************************/
int cardif_clear_keys(struct interface_data *intdata)
{
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
return -1;
}
void cardif_reassociate(struct interface_data *intiface, uint8_t reason)
{
debug_printf(DEBUG_EXCESSIVE, "%s not implemented.\n", __FUNCTION__);
}
void cardif_try_associate(struct interface_data *intiface)
{
debug_printf(DEBUG_EXCESSIVE, "%s not implemented!\n", __FUNCTION__);
}
void cardif_get_abilitites(struct interface_data *intdata)
{
intdata->enc_capa = 0;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -