📄 cardif_generic.c
字号:
return XENOWIRELESS;
}
/******************************************
*
* 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(context *thisint)
{
// Not sure if there is a good way to do this.
return TRUE;
}
/******************************************
*
* 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(context *thisint)
{
char nomac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
struct gen_sock_data *sockData;
struct config_network *network_data;
int pad;
sockData = thisint->sockData;
if (thisint == NULL) return XEMALLOC;
if (thisint->sendframe == NULL)
{
debug_printf(DEBUG_NORMAL, "Cannot send NULL frame!\n");
return XENOFRAMES;
}
if (thisint->send_size == 0) return XENONE;
network_data = config_get_network_config();
if (network_data == NULL)
{
debug_printf(DEBUG_NORMAL, "No valid network data available! Discarding packet!\n");
return XEGENERROR;
}
// 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);
}
if (thisint->send_size < 64)
{
pad = 64 - thisint->send_size;
debug_printf(DEBUG_INT, "Padding frame to 64 bytes by adding %d byte"
"(s).\n", pad);
memset(&thisint->sendframe[thisint->send_size+1], 0x00, pad);
thisint->send_size += pad;
}
debug_printf(DEBUG_EVERYTHING, "Frame to be sent (%d) : \n", thisint->send_size);
debug_hex_dump(DEBUG_EVERYTHING, thisint->sendframe, thisint->send_size);
if (pcap_sendpacket(sockData->pcap_descr, thisint->sendframe, thisint->send_size) < 0)
{
debug_printf(DEBUG_NORMAL, "Error sending frame!\n");
pcap_perror(sockData->pcap_descr, NULL);
return -1;
}
return XENONE; // We didn't get an error.
}
/******************************************
*
* Get a frame from the network. Since we are in promisc. mode, we will get
* frames that aren't intended for us. So, check the frame, determine if it
* is something we care about, and act accordingly.
*
******************************************/
int cardif_getframe(context *thisint)
{
int pcap_ret_val = 0;
char dot1x_default_dest[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
struct gen_sock_data *sockData;
uint8_t *resultframe = NULL;
struct pcap_pkthdr *pkt_header = NULL;
u_char *pkt_data = NULL;
sockData = thisint->sockData;
FREE(thisint->recvframe);
thisint->recv_size = 0;
resultframe = Malloc(1524);
if (resultframe == NULL)
{
debug_printf(DEBUG_NORMAL, "Couldn't allocate memory to store resulting frame!\n");
return XESOCKOP;
}
switch (pcap_next_ex(sockData->pcap_descr, &pkt_header, &pkt_data))
{
case 1:
// Everything went fine, move on.
break;
case 0:
return XEWINTIMEREXPIRED;
break;
case -1:
return XESOCKOP;
break;
case -2:
debug_printf(DEBUG_NORMAL, "Hit an EOF reading a pcap file!? This shouldn't happen!\n");
return XEGENERROR;
default:
debug_printf(DEBUG_NORMAL, "Unknown result came from pcap!\n");
return XEGENERROR;
}
// We have more frames available.
memcpy(resultframe, pkt_data, pkt_header->len);
debug_printf(DEBUG_EVERYTHING, "Got Frame : \n");
debug_hex_dump(DEBUG_EVERYTHING, resultframe, pkt_header->len);
//#warning FIX!
// 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)))
{
thisint->recv_size = pkt_header->len;
thisint->recvframe = resultframe;
return pkt_header->len;
}
// Otherwise it isn't for us.
debug_printf(DEBUG_INT, "Got a frame, not for us.\n");
FREE(resultframe);
return XENOFRAMES;
}
/******************************************
*
* Validate an interface, based on if it has a MAC address.
*
******************************************/
int cardif_validate(char *interf)
{
// Assume that the interface is valid, or the user wouldn't have
// told us to use it. ;)
return TRUE;
}
/*******************************************************
*
* Check to see if an interface is wireless. On linux, we look in
* /proc/net/wireless to see if the interface is registered with the
* wireless extensions.
*
*******************************************************/
int cardif_int_is_wireless(char *interf)
{
// Not ever going to be wireless!
return FALSE;
}
/******************************************************
*
* Stub for wireless scan.
*
*****************************************************/
int cardif_start_wireless_scan(context *thisint)
{
return XENONE;
}
/*****************************************************
*
* Stub for encryption capabilities.
*
*****************************************************/
void cardif_get_abilities(context *thisint)
{
thisint->enc_capa = 0;
}
/*****************************************************
*
* Stub for interface attachment
*
*****************************************************/
void cardif_wait_for_int(char *intname)
{
}
/*****************************************************
*
* Stub for clearing encryption keys
*
*****************************************************/
int cardif_clear_keys(context *intdata)
{
return XENONE;
}
/*****************************************************
*
* Stub for wireless disassociation
*
*****************************************************/
int cardif_disassociate(context *thisint, int reason_code)
{
return XENONE;
}
/*****************************************************
*
* Stub for passive scan timer callback
*
*****************************************************/
void cardif_passive_scan_timeout(context *ctx)
{
}
/*****************************************************
*
* Stub for deleting an encryption key
*
*****************************************************/
int cardif_delete_key(context *intdata, int key_idx, int set_tx)
{
return XENONE;
}
/*****************************************************
*
* Stub for disabling WPA association state
*
*****************************************************/
int cardif_disable_wpa_state(context *thisint)
{
return XENONE;
}
/*****************************************************
*
* Stub for wireless scanning
*
*****************************************************/
int cardif_do_wireless_scan(context *thisint, char passive)
{
return XENONE;
}
/*****************************************************
*
* Stub for disabling encryption
*
*****************************************************/
int cardif_enc_disable(context *intdata)
{
return XENONE;
}
/*****************************************************
*
* Stub for reassociating to a wireless network
*
*****************************************************/
void cardif_reassociate(context *intiface, uint8_t reason)
{
}
/*****************************************************
*
* Stub for setting WEP keys
*
*****************************************************/
int cardif_set_wep_key(context *thisint, uint8_t *key,
int keylen, int index)
{
}
/*****************************************************
*
* Stub for disassociate/roam
*
*****************************************************/
int cardif_wep_associate(context *thisint, int zeros)
{
return XENONE;
}
/*****************************************************
*
* Stub for setting CCMP keys
*
*****************************************************/
int cardif_set_ccmp_key(context *thisint, char *addr, int keyidx,
int settx, char *key, int keylen)
{
return XENONE;
}
/*****************************************************
*
* Stub for setting TKIP keys
*
*****************************************************/
int cardif_set_tkip_key(context *thisint, char *addr,
int keyidx, int settx, char *key, int keylen)
{
return XENONE;
}
/*****************************************************
*
* Stub for enabling/disabling rx of unencrypted frames on an interface
*
*****************************************************/
int cardif_drop_unencrypted(context *intdata, char endis)
{
return XENONE;
}
/*****************************************************
*
* Stub for getting the WPA-IE
*
*****************************************************/
int cardif_get_wpa_ie(context *intdata, char *iedata, int *ielen)
{
return XENONE;
}
/*****************************************************
*
* Stub for getting the RSN-IE
*
*****************************************************/
int cardif_get_wpa2_ie(context *intdata, char *iedata, int *ielen)
{
return XENONE;
}
/*****************************************************
*
* Stub for enabling/disabling countermeasures on an interface
*
*****************************************************/
int cardif_countermeasures(context *intdata, char endis)
{
return XENONE;
}
void cardif_operstate(context *ctx, uint8_t newstate)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -