summaryrefslogtreecommitdiffstats
path: root/drivers/sk98lin/skcsum.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sk98lin/skcsum.c')
-rw-r--r--drivers/sk98lin/skcsum.c483
1 files changed, 0 insertions, 483 deletions
diff --git a/drivers/sk98lin/skcsum.c b/drivers/sk98lin/skcsum.c
index a5dc572587..60d7e30136 100644
--- a/drivers/sk98lin/skcsum.c
+++ b/drivers/sk98lin/skcsum.c
@@ -261,489 +261,6 @@ static const char SysKonnectFileId[] = "@(#)"
* has been specified in the 'ProtocolFlags', the 16-bit Internet Checksum
* of the TCP or UDP pseudo header is returned here.
*/
-#if 0
-void SkCsGetSendInfo(
-SK_AC *pAc, /* Adapter context struct. */
-void *pIpHeader, /* IP header. */
-SKCS_PACKET_INFO *pPacketInfo, /* Packet information struct. */
-int NetNumber) /* Net number */
-{
- /* Internet Header Version found in IP header. */
- unsigned InternetHeaderVersion;
-
- /* Length of the IP header as found in IP header. */
- unsigned IpHeaderLength;
-
- /* Bit field specifiying the desired/found protocols. */
- unsigned ProtocolFlags;
-
- /* Next level protocol identifier found in IP header. */
- unsigned NextLevelProtocol;
-
- /* Length of IP data portion. */
- unsigned IpDataLength;
-
- /* TCP/UDP pseudo header checksum. */
- unsigned long PseudoHeaderChecksum;
-
- /* Pointer to next level protocol statistics structure. */
- SKCS_PROTO_STATS *NextLevelProtoStats;
-
- /* Temporary variable. */
- unsigned Tmp;
-
- Tmp = *(SK_U8 *)
- SKCS_IDX(pIpHeader, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH);
-
- /* Get the Internet Header Version (IHV). */
- /* Note: The IHV is stored in the upper four bits. */
-
- InternetHeaderVersion = Tmp >> 4;
-
- /* Check the Internet Header Version. */
- /* Note: We currently only support IP version 4. */
-
- if (InternetHeaderVersion != 4) { /* IPv4? */
- SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_TX,
- ("Tx: Unknown Internet Header Version %u.\n",
- InternetHeaderVersion));
- pPacketInfo->ProtocolFlags = 0;
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxUnableCts++;
- return;
- }
-
- /* Get the IP header length (IHL). */
- /*
- * Note: The IHL is stored in the lower four bits as the number of
- * 4-byte words.
- */
-
- IpHeaderLength = (Tmp & 0xf) * 4;
- pPacketInfo->IpHeaderLength = IpHeaderLength;
-
- /* Check the IP header length. */
-
- /* 04-Aug-1998 sw - Really check the IHL? Necessary? */
-
- if (IpHeaderLength < 5*4) {
- SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_TX,
- ("Tx: Invalid IP Header Length %u.\n", IpHeaderLength));
- pPacketInfo->ProtocolFlags = 0;
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxUnableCts++;
- return;
- }
-
- /* This is an IPv4 frame with a header of valid length. */
-
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxOkCts++;
-
- /* Check if we should calculate the IP header checksum. */
-
- ProtocolFlags = pPacketInfo->ProtocolFlags;
-
- if (ProtocolFlags & SKCS_PROTO_IP) {
- pPacketInfo->IpHeaderChecksum =
- SkCsCalculateChecksum(pIpHeader, IpHeaderLength);
- }
-
- /* Get the next level protocol identifier. */
-
- NextLevelProtocol =
- *(SK_U8 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_NEXT_LEVEL_PROTOCOL);
-
- /*
- * Check if this is a TCP or UDP frame and if we should calculate the
- * TCP/UDP pseudo header checksum.
- *
- * Also clear all protocol bit flags of protocols not present in the
- * frame.
- */
-
- if ((ProtocolFlags & SKCS_PROTO_TCP) != 0 &&
- NextLevelProtocol == SKCS_PROTO_ID_TCP) {
- /* TCP/IP frame. */
- ProtocolFlags &= SKCS_PROTO_TCP | SKCS_PROTO_IP;
- NextLevelProtoStats =
- &pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP];
- }
- else if ((ProtocolFlags & SKCS_PROTO_UDP) != 0 &&
- NextLevelProtocol == SKCS_PROTO_ID_UDP) {
- /* UDP/IP frame. */
- ProtocolFlags &= SKCS_PROTO_UDP | SKCS_PROTO_IP;
- NextLevelProtoStats =
- &pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP];
- }
- else {
- /*
- * Either not a TCP or UDP frame and/or TCP/UDP processing not
- * specified.
- */
- pPacketInfo->ProtocolFlags = ProtocolFlags & SKCS_PROTO_IP;
- return;
- }
-
- /* Check if this is an IP fragment. */
-
- /*
- * Note: An IP fragment has a non-zero "Fragment Offset" field and/or
- * the "More Fragments" bit set. Thus, if both the "Fragment Offset"
- * and the "More Fragments" are zero, it is *not* a fragment. We can
- * easily check both at the same time since they are in the same 16-bit
- * word.
- */
-
- if ((*(SK_U16 *)
- SKCS_IDX(pIpHeader, SKCS_OFS_IP_FLAGS_AND_FRAGMENT_OFFSET) &
- ~SKCS_IP_DONT_FRAGMENT) != 0) {
- /* IP fragment; ignore all other protocols. */
- pPacketInfo->ProtocolFlags = ProtocolFlags & SKCS_PROTO_IP;
- NextLevelProtoStats->TxUnableCts++;
- return;
- }
-
- /*
- * Calculate the TCP/UDP pseudo header checksum.
- */
-
- /* Get total length of IP header and data. */
-
- IpDataLength =
- *(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_TOTAL_LENGTH);
-
- /* Get length of IP data portion. */
-
- IpDataLength = SKCS_NTOH16(IpDataLength) - IpHeaderLength;
-
- /* Calculate the sum of all pseudo header fields (16-bit). */
-
- PseudoHeaderChecksum =
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_SOURCE_ADDRESS + 0) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_SOURCE_ADDRESS + 2) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_DESTINATION_ADDRESS + 0) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_DESTINATION_ADDRESS + 2) +
- (unsigned long) SKCS_HTON16(NextLevelProtocol) +
- (unsigned long) SKCS_HTON16(IpDataLength);
-
- /* Add-in any carries. */
-
- SKCS_OC_ADD(PseudoHeaderChecksum, PseudoHeaderChecksum, 0);
-
- /* Add-in any new carry. */
-
- SKCS_OC_ADD(pPacketInfo->PseudoHeaderChecksum, PseudoHeaderChecksum, 0);
-
- pPacketInfo->ProtocolFlags = ProtocolFlags;
- NextLevelProtoStats->TxOkCts++; /* Success. */
-} /* SkCsGetSendInfo */
-
-
-/******************************************************************************
- *
- * SkCsGetReceiveInfo - verify checksum information for a received packet
- *
- * Description:
- * Verify a received frame's checksum. The function returns a status code
- * reflecting the result of the verification.
- *
- * Note:
- * Before calling this function you have to verify that the frame is
- * not padded and Checksum1 and Checksum2 are bigger than 1.
- *
- * Arguments:
- * pAc - Pointer to adapter context struct.
- *
- * pIpHeader - Pointer to IP header. Must be at least the length in bytes
- * of the received IP header including any option fields. For UDP packets,
- * 8 additional bytes are needed to access the UDP checksum.
- *
- * Note: The actual length of the IP header is stored in the lower four
- * bits of the first octet of the IP header as the number of 4-byte words,
- * so it must be multiplied by four to get the length in bytes. Thus, the
- * maximum IP header length is 15 * 4 = 60 bytes.
- *
- * Checksum1 - The first 16-bit Internet Checksum calculated by the
- * hardware starting at the offset returned by SkCsSetReceiveFlags().
- *
- * Checksum2 - The second 16-bit Internet Checksum calculated by the
- * hardware starting at the offset returned by SkCsSetReceiveFlags().
- *
- * Returns:
- * SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
- * SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
- * SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
- * SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
- * SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
- * SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
- * SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
- * SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
- * SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
- * SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
- * SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
- *
- * Note: If SKCS_OVERWRITE_STATUS is defined, the SKCS_STATUS_XXX values
- * returned here can be defined in some header file by the module using CSUM.
- * In this way, the calling module can assign return values for its own needs,
- * e.g. by assigning bit flags to the individual protocols.
- */
-SKCS_STATUS SkCsGetReceiveInfo(
-SK_AC *pAc, /* Adapter context struct. */
-void *pIpHeader, /* IP header. */
-unsigned Checksum1, /* Hardware checksum 1. */
-unsigned Checksum2, /* Hardware checksum 2. */
-int NetNumber) /* Net number */
-{
- /* Internet Header Version found in IP header. */
- unsigned InternetHeaderVersion;
-
- /* Length of the IP header as found in IP header. */
- unsigned IpHeaderLength;
-
- /* Length of IP data portion. */
- unsigned IpDataLength;
-
- /* IP header checksum. */
- unsigned IpHeaderChecksum;
-
- /* IP header options checksum, if any. */
- unsigned IpOptionsChecksum;
-
- /* IP data checksum, i.e. TCP/UDP checksum. */
- unsigned IpDataChecksum;
-
- /* Next level protocol identifier found in IP header. */
- unsigned NextLevelProtocol;
-
- /* The checksum of the "next level protocol", i.e. TCP or UDP. */
- unsigned long NextLevelProtocolChecksum;
-
- /* Pointer to next level protocol statistics structure. */
- SKCS_PROTO_STATS *NextLevelProtoStats;
-
- /* Temporary variable. */
- unsigned Tmp;
-
- Tmp = *(SK_U8 *)
- SKCS_IDX(pIpHeader, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH);
-
- /* Get the Internet Header Version (IHV). */
- /* Note: The IHV is stored in the upper four bits. */
-
- InternetHeaderVersion = Tmp >> 4;
-
- /* Check the Internet Header Version. */
- /* Note: We currently only support IP version 4. */
-
- if (InternetHeaderVersion != 4) { /* IPv4? */
- SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
- ("Rx: Unknown Internet Header Version %u.\n",
- InternetHeaderVersion));
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
- return (SKCS_STATUS_UNKNOWN_IP_VERSION);
- }
-
- /* Get the IP header length (IHL). */
- /*
- * Note: The IHL is stored in the lower four bits as the number of
- * 4-byte words.
- */
-
- IpHeaderLength = (Tmp & 0xf) * 4;
-
- /* Check the IP header length. */
-
- /* 04-Aug-1998 sw - Really check the IHL? Necessary? */
-
- if (IpHeaderLength < 5*4) {
- SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
- ("Rx: Invalid IP Header Length %u.\n", IpHeaderLength));
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
- return (SKCS_STATUS_IP_CSUM_ERROR);
- }
-
- /* This is an IPv4 frame with a header of valid length. */
-
- /* Get the IP header and data checksum. */
-
- IpDataChecksum = Checksum2;
-
- /*
- * The IP header checksum is calculated as follows:
- *
- * IpHeaderChecksum = Checksum1 - Checksum2
- */
-
- SKCS_OC_SUB(IpHeaderChecksum, Checksum1, Checksum2);
-
- /* Check if any IP header options. */
-
- if (IpHeaderLength > SKCS_IP_HEADER_SIZE) {
-
- /* Get the IP options checksum. */
-
- IpOptionsChecksum = SkCsCalculateChecksum(
- SKCS_IDX(pIpHeader, SKCS_IP_HEADER_SIZE),
- IpHeaderLength - SKCS_IP_HEADER_SIZE);
-
- /* Adjust the IP header and IP data checksums. */
-
- SKCS_OC_ADD(IpHeaderChecksum, IpHeaderChecksum, IpOptionsChecksum);
-
- SKCS_OC_SUB(IpDataChecksum, IpDataChecksum, IpOptionsChecksum);
- }
-
- /*
- * Check if the IP header checksum is ok.
- *
- * NOTE: We must check the IP header checksum even if the caller just wants
- * us to check upper-layer checksums, because we cannot do any further
- * processing of the packet without a valid IP checksum.
- */
-
- /* Get the next level protocol identifier. */
-
- NextLevelProtocol = *(SK_U8 *)
- SKCS_IDX(pIpHeader, SKCS_OFS_IP_NEXT_LEVEL_PROTOCOL);
-
- if (IpHeaderChecksum != 0xFFFF) {
- pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
- /* the NDIS tester wants to know the upper level protocol too */
- if (NextLevelProtocol == SKCS_PROTO_ID_TCP) {
- return(SKCS_STATUS_IP_CSUM_ERROR_TCP);
- }
- else if (NextLevelProtocol == SKCS_PROTO_ID_UDP) {
- return(SKCS_STATUS_IP_CSUM_ERROR_UDP);
- }
- return (SKCS_STATUS_IP_CSUM_ERROR);
- }
-
- /*
- * Check if this is a TCP or UDP frame and if we should calculate the
- * TCP/UDP pseudo header checksum.
- *
- * Also clear all protocol bit flags of protocols not present in the
- * frame.
- */
-
- if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_TCP) != 0 &&
- NextLevelProtocol == SKCS_PROTO_ID_TCP) {
- /* TCP/IP frame. */
- NextLevelProtoStats =
- &pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP];
- }
- else if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_UDP) != 0 &&
- NextLevelProtocol == SKCS_PROTO_ID_UDP) {
- /* UDP/IP frame. */
- NextLevelProtoStats =
- &pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP];
- }
- else {
- /*
- * Either not a TCP or UDP frame and/or TCP/UDP processing not
- * specified.
- */
- return (SKCS_STATUS_IP_CSUM_OK);
- }
-
- /* Check if this is an IP fragment. */
-
- /*
- * Note: An IP fragment has a non-zero "Fragment Offset" field and/or
- * the "More Fragments" bit set. Thus, if both the "Fragment Offset"
- * and the "More Fragments" are zero, it is *not* a fragment. We can
- * easily check both at the same time since they are in the same 16-bit
- * word.
- */
-
- if ((*(SK_U16 *)
- SKCS_IDX(pIpHeader, SKCS_OFS_IP_FLAGS_AND_FRAGMENT_OFFSET) &
- ~SKCS_IP_DONT_FRAGMENT) != 0) {
- /* IP fragment; ignore all other protocols. */
- NextLevelProtoStats->RxUnableCts++;
- return (SKCS_STATUS_IP_FRAGMENT);
- }
-
- /*
- * 08-May-2000 ra
- *
- * From RFC 768 (UDP)
- * If the computed checksum is zero, it is transmitted as all ones (the
- * equivalent in one's complement arithmetic). An all zero transmitted
- * checksum value means that the transmitter generated no checksum (for
- * debugging or for higher level protocols that don't care).
- */
-
- if (NextLevelProtocol == SKCS_PROTO_ID_UDP &&
- *(SK_U16*)SKCS_IDX(pIpHeader, IpHeaderLength + 6) == 0x0000) {
-
- NextLevelProtoStats->RxOkCts++;
-
- return (SKCS_STATUS_IP_CSUM_OK_NO_UDP);
- }
-
- /*
- * Calculate the TCP/UDP checksum.
- */
-
- /* Get total length of IP header and data. */
-
- IpDataLength =
- *(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_TOTAL_LENGTH);
-
- /* Get length of IP data portion. */
-
- IpDataLength = SKCS_NTOH16(IpDataLength) - IpHeaderLength;
-
- NextLevelProtocolChecksum =
-
- /* Calculate the pseudo header checksum. */
-
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_SOURCE_ADDRESS + 0) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_SOURCE_ADDRESS + 2) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_DESTINATION_ADDRESS + 0) +
- (unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
- SKCS_OFS_IP_DESTINATION_ADDRESS + 2) +
- (unsigned long) SKCS_HTON16(NextLevelProtocol) +
- (unsigned long) SKCS_HTON16(IpDataLength) +
-
- /* Add the TCP/UDP header checksum. */
-
- (unsigned long) IpDataChecksum;
-
- /* Add-in any carries. */
-
- SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);
-
- /* Add-in any new carry. */
-
- SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);
-
- /* Check if the TCP/UDP checksum is ok. */
-
- if ((unsigned) NextLevelProtocolChecksum == 0xFFFF) {
-
- /* TCP/UDP checksum ok. */
-
- NextLevelProtoStats->RxOkCts++;
-
- return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
- SKCS_STATUS_TCP_CSUM_OK : SKCS_STATUS_UDP_CSUM_OK);
- }
-
- /* TCP/UDP checksum error. */
-
- NextLevelProtoStats->RxErrCts++;
-
- return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
- SKCS_STATUS_TCP_CSUM_ERROR : SKCS_STATUS_UDP_CSUM_ERROR);
-} /* SkCsGetReceiveInfo */
-#endif
/******************************************************************************