UA_Int32 Namespace_loadXml(Namespace **ns,UA_UInt32 nsid,const char* rootName, XML_Stack_Loader getNextBufferFull) { UA_Int32 retval = UA_SUCCESS; char buf[XML_BUFFER_LEN]; int len; /* len is the number of bytes in the current bufferful of data */ XML_Stack s; XML_Stack_init(&s, 0, rootName); UA_NodeSet n; UA_NodeSet_init(&n, 0); *ns = n.ns; XML_Stack_addChildHandler(&s, "UANodeSet", strlen("UANodeSet"), (XML_decoder) UA_NodeSet_decodeXmlFromStack, UA_INVALIDTYPE, &n); XML_Parser parser = XML_ParserCreate(UA_NULL); XML_SetUserData(parser, &s); XML_SetElementHandler(parser, XML_Stack_startElement, XML_Stack_endElement); XML_SetCharacterDataHandler(parser, XML_Stack_handleText); while ((len = getNextBufferFull(buf, XML_BUFFER_LEN)) > 0) { if (XML_Parse(parser, buf, len, (len < XML_BUFFER_LEN)) == XML_STATUS_ERROR) { retval = UA_ERR_INVALID_VALUE; break; } } XML_ParserFree(parser); DBG_VERBOSE(printf("Namespace_loadXml - aliases addr=%p, size=%d\n", (void*) &(n.aliases), n.aliases.size)); DBG_VERBOSE(UA_NodeSetAliases_println("Namespace_loadXml - elements=", &n.aliases)); return retval; }
void SetupDeviceForMulticast(struct et131x_adapter *pAdapter) { struct _RXMAC_t __iomem *rxmac = &pAdapter->CSRAddress->rxmac; uint32_t nIndex; uint32_t result; uint32_t hash1 = 0; uint32_t hash2 = 0; uint32_t hash3 = 0; uint32_t hash4 = 0; PM_CSR_t pm_csr; DBG_ENTER(et131x_dbginfo); /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision * the multi-cast LIST. If it is NOT specified, (and "ALL" is not * specified) then we should pass NO multi-cast addresses to the * driver. */ if (pAdapter->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) { DBG_VERBOSE(et131x_dbginfo, "MULTICAST flag is set, MCCount: %d\n", pAdapter->MCAddressCount); /* Loop through our multicast array and set up the device */ for (nIndex = 0; nIndex < pAdapter->MCAddressCount; nIndex++) { DBG_VERBOSE(et131x_dbginfo, "MCList[%d]: %02x:%02x:%02x:%02x:%02x:%02x\n", nIndex, pAdapter->MCList[nIndex][0], pAdapter->MCList[nIndex][1], pAdapter->MCList[nIndex][2], pAdapter->MCList[nIndex][3], pAdapter->MCList[nIndex][4], pAdapter->MCList[nIndex][5]); result = ether_crc(6, pAdapter->MCList[nIndex]); result = (result & 0x3F800000) >> 23; if (result < 32) { hash1 |= (1 << result); } else if ((31 < result) && (result < 64)) { result -= 32; hash2 |= (1 << result); } else if ((63 < result) && (result < 96)) { result -= 64; hash3 |= (1 << result); } else { result -= 96; hash4 |= (1 << result); } } }
UA_Int32 _UA_NodeId_copycstring(cstring src, UA_NodeId* dst, UA_NodeSetAliases* aliases) { UA_Int32 retval = UA_SUCCESS; if (src != UA_NULL && dst != UA_NULL ) { if (src[0] == 'i' && src[1] == '=') { // namespace zero numeric identifier dst->identifier.numeric = atoi(&src[2]); } else if (src[0] == 'n' && src[1] == 's' && src[2] == '=') { // namespace dst->namespaceIndex = atoi(&src[3]); src = strchr(&src[3],';'); if (src != UA_NULL) retval = _UA_NodeId_copycstring(src+1,dst,aliases); // +1 to start beyond ; else retval = UA_ERR_INVALID_VALUE; } else if (aliases != UA_NULL ) { // try for aliases UA_Int32 i; for (i = 0; i < aliases->size && dst->identifier.numeric == 0; ++i) { if (0 == strncmp((char const*) src, (char const*) aliases->aliases[i]->alias.data, aliases->aliases[i]->alias.length)) { _UA_NodeId_copycstring((cstring)aliases->aliases[i]->alias.data,dst,UA_NULL); // substitute text of alias } } } else { retval = UA_ERR_NOT_IMPLEMENTED; } } else { retval = UA_ERR_INVALID_VALUE; } DBG_VERBOSE(printf("UA_NodeId_copycstring src=%s,id=%d\n", src, dst->identifier.numeric)); return retval; }
static int recv_message(void *buf, size_t size) { uint8_t *iter = buf; struct ste_message *msg = buf; do { DBG_VERBOSE("size %zu msg->len %u.", size, msg->len); if (size < sizeof(*msg)) { sap_error("invalid message received (%zu bytes)", size); return -EBADMSG; } /* Message must be complete. */ if (size < (msg->len + sizeof(msg->len))) { sap_error("incomplete message received (%zu bytes)", size); return -EBADMSG; } recv_response(msg); /* Reduce total buffer size by just handled frame size. */ size -= msg->len + sizeof(msg->len); /* Move msg pointer to the next message if any. */ iter += msg->len + sizeof(msg->len); msg = (struct ste_message *)iter; } while (size > 0); return 0; }
/** * et131x_tx - The handler to tx a packet on the device * @skb: data to be Tx'd * @netdev: device on which data is to be Tx'd * * Returns 0 on success, errno on failure (as defined in errno.h) */ int et131x_tx(struct sk_buff *skb, struct net_device *netdev) { int status = 0; DBG_TX_ENTER(et131x_dbginfo); /* Save the timestamp for the TX timeout watchdog */ netdev->trans_start = jiffies; /* Call the device-specific data Tx routine */ status = et131x_send_packets(skb, netdev); /* Check status and manage the netif queue if necessary */ if (status != 0) { if (status == -ENOMEM) { DBG_VERBOSE(et131x_dbginfo, "OUT OF TCBs; STOP NETIF QUEUE\n"); /* Put the queue to sleep until resources are * available */ netif_stop_queue(netdev); status = NETDEV_TX_BUSY; } else { DBG_WARNING(et131x_dbginfo, "Misc error; drop packet\n"); status = NETDEV_TX_OK; } } DBG_TX_LEAVE(et131x_dbginfo); return status; }
UA_Int32 UA_ExpandedNodeId_copycstring(cstring src, UA_ExpandedNodeId *dst, UA_NodeSetAliases *aliases) { dst->nodeId.namespaceIndex = 0; dst->nodeId.identifierType = UA_NODEIDTYPE_NUMERIC; dst->nodeId.identifier.numeric = 0; UA_NodeId_copycstring(src, &(dst->nodeId), aliases); DBG_VERBOSE(printf("UA_ExpandedNodeId_copycstring src=%s,id=%d\n", src, dst->nodeId.identifier.numeric)); return UA_SUCCESS; }
/** * et131x_ioctl_mii - The function which handles MII IOCTLs * @netdev: device on which the query is being made * @reqbuf: the request-specific data buffer * @cmd: the command request code * * Returns 0 on success, errno on failure (as defined in errno.h) */ int et131x_ioctl_mii(struct net_device *netdev, struct ifreq *reqbuf, int cmd) { int status = 0; struct et131x_adapter *pAdapter = netdev_priv(netdev); struct mii_ioctl_data *data = if_mii(reqbuf); DBG_ENTER(et131x_dbginfo); switch (cmd) { case SIOCGMIIPHY: DBG_VERBOSE(et131x_dbginfo, "SIOCGMIIPHY\n"); data->phy_id = pAdapter->Stats.xcvr_addr; break; case SIOCGMIIREG: DBG_VERBOSE(et131x_dbginfo, "SIOCGMIIREG\n"); if (!capable(CAP_NET_ADMIN)) { status = -EPERM; } else { status = MiRead(pAdapter, data->reg_num, &data->val_out); } break; case SIOCSMIIREG: DBG_VERBOSE(et131x_dbginfo, "SIOCSMIIREG\n"); if (!capable(CAP_NET_ADMIN)) { status = -EPERM; } else { status = MiWrite(pAdapter, data->reg_num, data->val_in); } break; default: status = -EOPNOTSUPP; } DBG_LEAVE(et131x_dbginfo); return status; }
static int send_message(GIOChannel *io, void *buf, size_t size) { gsize written; DBG_VERBOSE("io %p, size %zu", io, size); if (g_io_channel_write_chars(io, buf, size, &written, NULL) != G_IO_STATUS_NORMAL) return -EIO; return written; }
void sap_transfer_apdu_req(void *sap_device, struct sap_parameter *param) { uint8_t result; DBG_VERBOSE("sap_device %p param %p", sap_device, param); if (u8500.state != STE_ENABLED) { result = get_sap_result(STE_SEND_APDU_MSG, STE_STATUS_FAILURE); sap_transfer_apdu_rsp(sap_device, result, NULL, 0); return; } if (send_request(u8500.io, STE_SEND_APDU_REQ, param) < 0) sap_transfer_apdu_rsp(sap_device, SAP_RESULT_ERROR_NO_DATA, NULL, 0); }
UA_Int32 UA_Text_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Byte **dst, _Bool isStart) { DBG_VERBOSE(printf("UA_String entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); UA_UInt32 i; if(isStart) { if(dst == UA_NULL) { UA_alloc((void **)&dst, sizeof(void *)); s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; } // set attributes for(i = 0;attr[i];i += 2) { if(0 == strncmp("Data", attr[i], strlen("Data"))) { char *tmp; UA_alloc((void **)&tmp, strlen(attr[i+1])+1); strncpy(tmp, attr[i+1], strlen(attr[i+1])); tmp[strlen(attr[i+1])] = 0; *dst = (UA_Byte *)tmp; } else printf("UA_Text_decodeXml - Unknown attribute - name=%s, value=%s\n", attr[i], attr[i+1]); } } return UA_SUCCESS; }
static int send_request(GIOChannel *io, uint16_t id, struct sap_parameter *param) { int ret; struct ste_message *msg; size_t size = sizeof(*msg); DBG_VERBOSE("io %p", io); if (param) size += param->len; msg = g_try_malloc0(size); if (!msg) { sap_error("sending request failed: %s", strerror(ENOMEM)); return -ENOMEM; } msg->len = size - sizeof(msg->len); msg->id = id; msg->client_tag = STE_CLIENT_TAG; if (param) memcpy(msg->payload, param->val, param->len); ret = send_message(io, msg, size); if (ret < 0) { sap_error("sending request failed: %s", strerror(-ret)); } else if (ret != (int) size) { sap_error("sending request failed: %d out of %zu bytes sent", ret, size); ret = -EIO; } g_free(msg); return ret; }
/****************************************************************************** ROUTINE : et131x_config_parse ****************************************************************************** DESCRIPTION : Parses a configuration from some location (module parameters, for example) into the private adapter struct PARAMETERS : pAdapter - pointer to the private adapter struct RETURNS : N/A REUSE INFORMATION : *****************************************************************************/ void et131x_config_parse( ET131X_ADAPTER *pAdapter ) { UINT8 macAddrDef[] = PARM_MAC_ADDRESS_DEF; /*-----------------------------------------------------------------------*/ DBG_FUNC( "et131x_config_parse" ); DBG_ENTER( et131x_dbginfo ); /************************************************************************** The NDIS driver uses the registry to store persistent per-device configuration, and reads this configuration into the appropriate elements of the private adapter structure on initialization. Because Linux has no analog to the registry, use this function to initialize the private adapter structure with a default configuration. One other possibility is to use a series of module parameters which can be passed in by the caller when the module is initialized. However, this implementation does not allow for seperate configurations in the event multiple devices are present, and hence will not suffice. If another method is derived which addresses this problem, this is where it should be implemented. *************************************************************************/ /************************************************************************** Set the private adapter struct with default values for the corresponding parameters *************************************************************************/ if( et131x_speed_set != PARM_SPEED_DUPLEX_DEF ) { DBG_VERBOSE( et131x_dbginfo, "Speed set manually to : %d \n",et131x_speed_set ); pAdapter->SpeedDuplex = et131x_speed_set; } else { pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; } // pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; pAdapter->RegistryVlanTag = PARM_VLAN_TAG_DEF; pAdapter->RegistryFlowControl = PARM_FLOW_CTL_DEF; pAdapter->RegistryWOLLink = PARM_WOL_LINK_DEF; pAdapter->RegistryWOLMatch = PARM_WOL_MATCH_DEF; pAdapter->RegistryJumboPacket = PARM_JUMBO_PKT_DEF; pAdapter->RegistryPhyComa = PARM_PHY_COMA_DEF; pAdapter->RegistryRxNumBuffers = PARM_RX_NUM_BUFS_DEF; pAdapter->RegistryRxTimeInterval = PARM_RX_TIME_INT_DEF; pAdapter->RegistryTxNumBuffers = PARM_TX_NUM_BUFS_DEF; pAdapter->RegistryTxTimeInterval = PARM_TX_TIME_INT_DEF; pAdapter->RegistryRxMemEnd = PARM_RX_MEM_END_DEF; pAdapter->RegistryMACStat = PARM_MAC_STAT_DEF; pAdapter->RegistrySCGain = PARM_SC_GAIN_DEF; pAdapter->RegistryPMWOL = PARM_PM_WOL_DEF; if( et131x_nmi_disable != PARM_NMI_DISABLE_DEF ) { pAdapter->RegistryNMIDisable = et131x_nmi_disable; } else { pAdapter->RegistryNMIDisable = PARM_NMI_DISABLE_DEF; } pAdapter->RegistryDMACache = PARM_DMA_CACHE_DEF; pAdapter->RegistryPhyLoopbk = PARM_PHY_LOOPBK_DEF; /************************************************************************** Set the MAC address to a default *************************************************************************/ memcpy( pAdapter->CurrentAddress, macAddrDef, ETH_ALEN ); pAdapter->bOverrideAddress = FALSE; DBG_TRACE( et131x_dbginfo, "Default MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n", pAdapter->CurrentAddress[0], pAdapter->CurrentAddress[1], pAdapter->CurrentAddress[2], pAdapter->CurrentAddress[3], pAdapter->CurrentAddress[4], pAdapter->CurrentAddress[5] ); /************************************************************************** Decode SpeedDuplex Set up as if we are auto negotiating always and then change if we go into force mode *************************************************************************/ pAdapter->AiForceSpeed = 0; // Auto speed pAdapter->AiForceDpx = 0; // Auto FDX /************************************************************************** If we are the 10/100 device, and gigabit is somehow requested then knock it down to 100 full. *************************************************************************/ if(( pAdapter->DeviceID == ET131X_PCI_DEVICE_ID_FAST ) && ( pAdapter->SpeedDuplex == 5 )) { pAdapter->SpeedDuplex = 4; } switch( pAdapter->SpeedDuplex ) { case 1: // 10Mb Half-Duplex pAdapter->AiForceSpeed = 10; pAdapter->AiForceDpx = 1; break; case 2: // 10Mb Full-Duplex pAdapter->AiForceSpeed = 10; pAdapter->AiForceDpx = 2; break; case 3: // 100Mb Half-Duplex pAdapter->AiForceSpeed = 100; pAdapter->AiForceDpx = 1; break; case 4: // 100Mb Full-Duplex pAdapter->AiForceSpeed = 100; pAdapter->AiForceDpx = 2; break; case 5: // 1000Mb Full-Duplex pAdapter->AiForceSpeed = 1000; pAdapter->AiForceDpx = 2; break; } DBG_LEAVE( et131x_dbginfo ); return; }
static void recv_response(struct ste_message *msg) { uint32_t status; uint8_t *param; DBG_VERBOSE("msg_id 0x%x", msg->id); if (msg->id == STE_END_SAP_RSP) { sap_disconnect_rsp(u8500.sap_data); simd_close(); return; } param = msg->payload; status = *(uint32_t *)param; param += sizeof(status); DBG_VERBOSE("status 0x%x", status); switch (msg->id) { case STE_START_SAP_RSP: if (status == STE_STATUS_OK) { sap_connect_rsp(u8500.sap_data, SAP_STATUS_OK, 0); } else { sap_connect_rsp(u8500.sap_data, SAP_STATUS_CONNECTION_FAILED, 0); simd_close(); } break; case STE_SEND_APDU_RSP: recv_pdu(STE_SEND_APDU_MSG, msg, status, param, sap_transfer_apdu_rsp); break; case STE_GET_ATR_RSP: recv_pdu(STE_GET_ATR_MSG, msg, status, param, sap_transfer_atr_rsp); break; case STE_POWER_OFF_RSP: recv_state_change(STE_POWER_OFF_MSG, status, STE_POWERED_OFF, sap_power_sim_off_rsp); break; case STE_POWER_ON_RSP: recv_state_change(STE_POWER_ON_MSG, status, STE_ENABLED, sap_power_sim_on_rsp); break; case STE_RESET_RSP: recv_state_change(STE_RESET_MSG, status, STE_ENABLED, sap_reset_sim_rsp); break; case STE_GET_STATUS_RSP: recv_card_status(status, param); break; case STE_STATUS_IND: recv_status(status); break; default: sap_error("unsupported message received (id 0x%x)", msg->id); } }
void response_split_task(void * arg) { client_info_t * client = arg; DBG_FUNC_ENTER(); DBG_VERBOSE("%s: client: %p\n", __FUNCTION__, client); /* variables for handling response split */ char temp[1024]; uint32_t temp_len = 0; read_stages_t stage = HEADER_LEN_READ; uint32_t payload_offset = 0; response_t * resp = NULL; uint32_t rem_size = 0; txn_buf_t * cur_buf = NULL; while (1) { if (cur_buf != NULL) { DBG_ALLOC("%s: FREE cur_buf->buf: %p cur_buf: %p\n", __FUNCTION__, cur_buf->buf, cur_buf); free(cur_buf->buf); free(cur_buf); cur_buf = NULL; } cur_buf = (txn_buf_t *)queue_pop(client->buf_q); DBG_VERBOSE("%s: buf: %p len: %ld offset: %ld\n", __FUNCTION__, cur_buf->buf, cur_buf->len, cur_buf->offset); /* write a response split using fixed len */ rem_size = cur_buf->len - cur_buf->offset; DBG_VERBOSE("rem_size: %u\n", rem_size); while ((temp_len > 0) && (rem_size > 0)) { switch(stage) { case HEADER_LEN_READ: { uint32_t hdr_len = 0; if ((rem_size + temp_len) < HEADER_SIZE) { memcpy(temp + temp_len, cur_buf->buf + cur_buf->offset, rem_size); temp_len += rem_size; rem_size = 0; } else { resp = malloc(sizeof(response_t)); assert(resp != NULL); DBG_ALLOC("%s: ALLOC request: %p\n", __FUNCTION__, resp); resp->buf = NULL; if (temp_len < HEADER_SIZE) { memcpy((uint8_t *)&hdr_len, temp, temp_len); memcpy(((uint8_t *)&hdr_len) + temp_len, cur_buf->buf + cur_buf->offset, HEADER_SIZE - temp_len); DBG_VERBOSE("HEADER length: %u\n", hdr_len); temp_len = 0; rem_size -= HEADER_SIZE + temp_len; } else { memcpy((uint8_t *)&hdr_len, temp, HEADER_SIZE); temp_len -= HEADER_SIZE; } resp->header_len = hdr_len; stage = HEADER_READ; } break; } case HEADER_READ: { if ((rem_size + temp_len) < resp->header_len) { memcpy(temp + temp_len, cur_buf->buf + cur_buf->offset, rem_size); temp_len += rem_size; rem_size = 0; } else { if (temp_len < resp->header_len) { memcpy((uint8_t *)&resp->hdr, temp, temp_len); memcpy(((uint8_t *)&resp->hdr) + temp_len, cur_buf->buf + cur_buf->offset, resp->header_len - temp_len); temp_len = 0; rem_size -= (resp->header_len - temp_len); } else { memcpy((uint8_t *)&resp->hdr, temp, resp->header_len); DBG_VERBOSE("REQUEST id: %u\n", resp->hdr.id); temp_len -= resp->header_len; } stage = PAYLOAD_READ; resp->buf = malloc(resp->hdr.len); assert(resp->buf != NULL); } break; } case PAYLOAD_READ: { if (temp_len < resp->hdr.len) { memcpy(resp->buf, temp, temp_len); temp_len = 0; } break; } default: DBG_ERR("INVALID case needs to be find out"); assert(0); break; } } while (rem_size > 0) { switch(stage) { case HEADER_LEN_READ: if (rem_size < HEADER_SIZE){ memcpy(temp, cur_buf->buf + cur_buf->offset, rem_size); temp_len = rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { resp = malloc(sizeof(response_t)); assert(resp != NULL); DBG_PRINT("Allocated resp: %p\n", resp); resp->buf = NULL; read_uint32_t((uint8_t *)cur_buf->buf + cur_buf->offset, HEADER_SIZE, &resp->header_len); cur_buf->offset += HEADER_SIZE; rem_size -= HEADER_SIZE; DBG_VERBOSE("HEADER: %u\n", resp->header_len); stage = HEADER_READ; } break; case HEADER_READ: if (rem_size < resp->header_len) { memcpy(temp, cur_buf->buf + cur_buf->offset, rem_size); temp_len = rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { read_pkt_hdr((uint8_t *)cur_buf->buf + cur_buf->offset, resp->header_len, &resp->hdr); DBG_VERBOSE("HEADER: %x %x %x %x\n", resp->hdr.magic, resp->hdr.len, resp->hdr.id, resp->hdr.future); rem_size -= resp->header_len; resp->buf = malloc(resp->hdr.len); assert(resp->buf != NULL); DBG_ALLOC("ALLOC resp->buf: %p\n", resp->buf); cur_buf->offset += resp->header_len; stage = PAYLOAD_READ; } break; case PAYLOAD_READ: { size_t len_to_read = resp->hdr.len - payload_offset; if (rem_size < len_to_read) { memcpy(resp->buf + payload_offset, cur_buf->buf + cur_buf->offset, rem_size); payload_offset += rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { memcpy(resp->buf + payload_offset, cur_buf->buf + cur_buf->offset, len_to_read); payload_offset = 0; rem_size -= len_to_read; cur_buf->offset += len_to_read; /* request is done, lets push it into the queue */ DBG_VERBOSE("GOT THE RESPONSE for ID: %u\n", resp->hdr.id); queue_push(client->res_q, (void *)resp); resp = NULL; stage = HEADER_LEN_READ; } } break; default: DBG_ERR("Invalid stage\n"); assert(0); } } } DBG_FUNC_EXIT(); }
/****************************************************************************** ROUTINE : SetupDeviceForMulticast ****************************************************************************** DESCRIPTION : Use to set the ET1310 to do multicast filtering PARAMETERS : pAdapter - pointer to our adapter structure RETURNS : NONE REUSE INFORMATION : NONE *****************************************************************************/ void SetupDeviceForMulticast( ET131X_ADAPTER *pAdapter ) { UINT32 nIndex; UINT32 result; RXMAC_MULTI_HASH_t hash1 = {0}; RXMAC_MULTI_HASH_t hash2 = {0}; RXMAC_MULTI_HASH_t hash3 = {0}; RXMAC_MULTI_HASH_t hash4 = {0}; /*-----------------------------------------------------------------------*/ DBG_FUNC( "SetupDeviceForMulticast" ); DBG_ENTER( et131x_dbginfo ); /************************************************************************** If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision the multi-cast LIST. If it is NOT specified, (and "ALL" is not specified) then we should pass NO multi-cast addresses to the driver. *************************************************************************/ if( pAdapter->PacketFilter & ET131X_PACKET_TYPE_MULTICAST ) { DBG_VERBOSE( et131x_dbginfo, "MULTICAST flag is set, MCCount: %d\n", pAdapter->MCAddressCount ); /********************************************************************** Loop through our multicast array and set up the device **********************************************************************/ for( nIndex = 0; nIndex < pAdapter->MCAddressCount; nIndex++ ) { DBG_VERBOSE( et131x_dbginfo, "MCList[%d]: %02x:%02x:%02x:%02x:%02x:%02x\n", nIndex, pAdapter->MCList[nIndex][0], pAdapter->MCList[nIndex][1], pAdapter->MCList[nIndex][2], pAdapter->MCList[nIndex][3], pAdapter->MCList[nIndex][4], pAdapter->MCList[nIndex][5] ); result = et131x_calc_enet_crc( pAdapter->MCList[nIndex], 6 ); result = ( result & 0x3F800000 ) >> 23; if( result < 32 ) { hash1.hash |= ( 1 << result ); } else if(( 31 < result ) && ( result < 64 )) { result -= 32; hash2.hash |= ( 1 << result ); } else if(( 63 < result ) && ( result < 96 )) { result -= 64; hash3.hash |= ( 1 << result ); } else { result -= 96; hash4.hash |= ( 1 << result ); } } }
/** * et131x_config_parse * @pAdapter: pointer to the private adapter struct * * Parses a configuration from some location (module parameters, for example) * into the private adapter struct */ void et131x_config_parse(struct et131x_adapter *pAdapter) { uint8_t macAddrDef[] = PARM_MAC_ADDRESS_DEF; DBG_ENTER(et131x_dbginfo); /* * The NDIS driver uses the registry to store persistent per-device * configuration, and reads this configuration into the appropriate * elements of the private adapter structure on initialization. * Because Linux has no analog to the registry, use this function to * initialize the private adapter structure with a default * configuration. * * One other possibility is to use a series of module parameters which * can be passed in by the caller when the module is initialized. * However, this implementation does not allow for seperate * configurations in the event multiple devices are present, and hence * will not suffice. * * If another method is derived which addresses this problem, this is * where it should be implemented. */ /* Set the private adapter struct with default values for the * corresponding parameters */ if (et131x_speed_set != PARM_SPEED_DUPLEX_DEF) { DBG_VERBOSE(et131x_dbginfo, "Speed set manually to : %d \n", et131x_speed_set); pAdapter->SpeedDuplex = et131x_speed_set; } else { pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; } // pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; pAdapter->RegistryVlanTag = PARM_VLAN_TAG_DEF; pAdapter->RegistryFlowControl = PARM_FLOW_CTL_DEF; pAdapter->RegistryJumboPacket = PARM_JUMBO_PKT_DEF; pAdapter->RegistryPhyComa = PARM_PHY_COMA_DEF; pAdapter->RegistryMACStat = PARM_MAC_STAT_DEF; if (et131x_nmi_disable != PARM_NMI_DISABLE_DEF) { pAdapter->RegistryNMIDisable = et131x_nmi_disable; } else { pAdapter->RegistryNMIDisable = PARM_NMI_DISABLE_DEF; } pAdapter->RegistryPhyLoopbk = PARM_PHY_LOOPBK_DEF; /* Set the MAC address to a default */ memcpy(pAdapter->CurrentAddress, macAddrDef, ETH_ALEN); pAdapter->bOverrideAddress = false; DBG_TRACE(et131x_dbginfo, "Default MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n", pAdapter->CurrentAddress[0], pAdapter->CurrentAddress[1], pAdapter->CurrentAddress[2], pAdapter->CurrentAddress[3], pAdapter->CurrentAddress[4], pAdapter->CurrentAddress[5]); /* Decode SpeedDuplex * * Set up as if we are auto negotiating always and then change if we * go into force mode */ pAdapter->AiForceSpeed = 0; // Auto speed pAdapter->AiForceDpx = 0; // Auto FDX /* If we are the 10/100 device, and gigabit is somehow requested then * knock it down to 100 full. */ if ((pAdapter->pdev->device == ET131X_PCI_DEVICE_ID_FAST) && (pAdapter->SpeedDuplex == 5)) { pAdapter->SpeedDuplex = 4; } switch (pAdapter->SpeedDuplex) { case 1: // 10Mb Half-Duplex pAdapter->AiForceSpeed = 10; pAdapter->AiForceDpx = 1; break; case 2: // 10Mb Full-Duplex pAdapter->AiForceSpeed = 10; pAdapter->AiForceDpx = 2; break; case 3: // 100Mb Half-Duplex pAdapter->AiForceSpeed = 100; pAdapter->AiForceDpx = 1; break; case 4: // 100Mb Full-Duplex pAdapter->AiForceSpeed = 100; pAdapter->AiForceDpx = 2; break; case 5: // 1000Mb Full-Duplex pAdapter->AiForceSpeed = 1000; pAdapter->AiForceDpx = 2; break; } DBG_LEAVE(et131x_dbginfo); }
/* * Parse the REST header and verify that the entire message * has been received (based on the length in the header). * * Corner case: short data terminates in middle of string * leaving what looks to be a valid identifier. * * Currently assumes a single space separates fields. */ cs_rest_status_t cs_rest_header_parse(uint8_t *buffer, int len, cs_rest_header_t *hdr, char **error_str) { char *dummy; char *token; int i; char parse_hdr[REST_HEADER_MAX]; int found_type; memset(hdr, 0, sizeof(*hdr)); /* In case error_str pointer isn't passed, give it a dummy value */ if (error_str == NULL) { error_str = &dummy; } *error_str = error_strs[0]; if (len < REST_OP_LEN + CS_URI_PREFIX_LEN) { return CS_REST_MORE_DATA; } strncpy(parse_hdr, (char *)buffer, REST_HEADER_MAX - 1); strncpy((char *)(hdr->packed_header), parse_hdr, REST_HEADER_MAX - 1); _CHECK_TOKEN(token, parse_hdr, hdr); /* OP */ strcpy(hdr->op, token); _CHECK_TOKEN(token, NULL, hdr); /* URI */ strncpy(hdr->uri, token, REST_URI_MAX); _CHECK_TOKEN(token, NULL, hdr); /* Transaction ID */ hdr->transaction_id = strtoul(token, NULL, 10); _CHECK_TOKEN(token, NULL, hdr); hdr->status_code = strtoul(token, NULL, 0); _CHECK_TOKEN(token, NULL, hdr); /* JSON Length */ hdr->json_length = strtoul(token, NULL, 10); found_type = false; DBG_VERBOSE("Looking for %s %s\n", hdr->op, hdr->uri); for (i = 0; i < rest_request_list_length; i++) { if (!strcmp(hdr->op, rest_request_list[i].op)) { if (!strcmp(hdr->uri, rest_request_list[i].uri)) { found_type = true; break; } } } if (!found_type) { *error_str = error_strs[4]; return CS_REST_NOT_ALLOWED; } /* Make sure entire json part of packet is present */ if (len < hdr->header_length + hdr->json_length) { return CS_REST_MORE_DATA; } return CS_REST_OKAY; }
/** * et131x_multicast - The handler to configure multicasting on the interface * @netdev: a pointer to a net_device struct representing the device */ void et131x_multicast(struct net_device *netdev) { struct et131x_adapter *adapter = netdev_priv(netdev); uint32_t PacketFilter = 0; uint32_t count; unsigned long lockflags; struct dev_mc_list *mclist = netdev->mc_list; DBG_ENTER(et131x_dbginfo); spin_lock_irqsave(&adapter->Lock, lockflags); /* Before we modify the platform-independent filter flags, store them * locally. This allows us to determine if anything's changed and if * we even need to bother the hardware */ PacketFilter = adapter->PacketFilter; /* Clear the 'multicast' flag locally; becuase we only have a single * flag to check multicast, and multiple multicast addresses can be * set, this is the easiest way to determine if more than one * multicast address is being set. */ PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST; /* Check the net_device flags and set the device independent flags * accordingly */ DBG_VERBOSE(et131x_dbginfo, "MULTICAST ADDR COUNT: %d\n", netdev->mc_count); if (netdev->flags & IFF_PROMISC) { DBG_VERBOSE(et131x_dbginfo, "Request: PROMISCUOUS MODE ON\n"); adapter->PacketFilter |= ET131X_PACKET_TYPE_PROMISCUOUS; } else { DBG_VERBOSE(et131x_dbginfo, "Request: PROMISCUOUS MODE OFF\n"); adapter->PacketFilter &= ~ET131X_PACKET_TYPE_PROMISCUOUS; } if (netdev->flags & IFF_ALLMULTI) { DBG_VERBOSE(et131x_dbginfo, "Request: ACCEPT ALL MULTICAST\n"); adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST; } if (netdev->mc_count > NIC_MAX_MCAST_LIST) { DBG_WARNING(et131x_dbginfo, "ACCEPT ALL MULTICAST for now, as there's more Multicast " "addresses than the HW supports\n"); adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST; } if (netdev->mc_count < 1) { DBG_VERBOSE(et131x_dbginfo, "Request: REJECT ALL MULTICAST\n"); adapter->PacketFilter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST; adapter->PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST; } else { DBG_VERBOSE(et131x_dbginfo, "Request: SET MULTICAST FILTER(S)\n"); adapter->PacketFilter |= ET131X_PACKET_TYPE_MULTICAST; } /* Set values in the private adapter struct */ adapter->MCAddressCount = netdev->mc_count; if (netdev->mc_count) { if (mclist->dmi_addrlen != ETH_ALEN) { DBG_WARNING(et131x_dbginfo, "Multicast addrs are not ETH_ALEN in size\n"); } else { count = netdev->mc_count - 1; memcpy(adapter->MCList[count], mclist->dmi_addr, ETH_ALEN); } } /* Are the new flags different from the previous ones? If not, then no * action is required * * NOTE - This block will always update the MCList with the hardware, * even if the addresses aren't the same. */ if (PacketFilter != adapter->PacketFilter) { /* Call the device's filter function */ DBG_VERBOSE(et131x_dbginfo, "UPDATE REQUIRED, FLAGS changed\n"); et131x_set_packet_filter(adapter); } else { DBG_VERBOSE(et131x_dbginfo, "NO UPDATE REQUIRED, FLAGS didn't change\n"); } spin_unlock_irqrestore(&adapter->Lock, lockflags); DBG_LEAVE(et131x_dbginfo); }
/** * et131x_set_packet_filter - Configures the Rx Packet filtering on the device * @adapter: pointer to our private adapter structure * * Returns 0 on success, errno on failure */ int et131x_set_packet_filter(struct et131x_adapter *adapter) { int status = 0; uint32_t filter = adapter->PacketFilter; RXMAC_CTRL_t ctrl; RXMAC_PF_CTRL_t pf_ctrl; DBG_ENTER(et131x_dbginfo); ctrl.value = readl(&adapter->CSRAddress->rxmac.ctrl.value); pf_ctrl.value = readl(&adapter->CSRAddress->rxmac.pf_ctrl.value); /* Default to disabled packet filtering. Enable it in the individual * case statements that require the device to filter something */ ctrl.bits.pkt_filter_disable = 1; /* Set us to be in promiscuous mode so we receive everything, this * is also true when we get a packet filter of 0 */ if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) { pf_ctrl.bits.filter_broad_en = 0; pf_ctrl.bits.filter_multi_en = 0; pf_ctrl.bits.filter_uni_en = 0; } else { /* * Set us up with Multicast packet filtering. Three cases are * possible - (1) we have a multi-cast list, (2) we receive ALL * multicast entries or (3) we receive none. */ if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) { DBG_VERBOSE(et131x_dbginfo, "Multicast filtering OFF (Rx ALL MULTICAST)\n"); pf_ctrl.bits.filter_multi_en = 0; } else { DBG_VERBOSE(et131x_dbginfo, "Multicast filtering ON\n"); SetupDeviceForMulticast(adapter); pf_ctrl.bits.filter_multi_en = 1; ctrl.bits.pkt_filter_disable = 0; } /* Set us up with Unicast packet filtering */ if (filter & ET131X_PACKET_TYPE_DIRECTED) { DBG_VERBOSE(et131x_dbginfo, "Unicast Filtering ON\n"); SetupDeviceForUnicast(adapter); pf_ctrl.bits.filter_uni_en = 1; ctrl.bits.pkt_filter_disable = 0; } /* Set us up with Broadcast packet filtering */ if (filter & ET131X_PACKET_TYPE_BROADCAST) { DBG_VERBOSE(et131x_dbginfo, "Broadcast Filtering ON\n"); pf_ctrl.bits.filter_broad_en = 1; ctrl.bits.pkt_filter_disable = 0; } else { DBG_VERBOSE(et131x_dbginfo, "Broadcast Filtering OFF\n"); pf_ctrl.bits.filter_broad_en = 0; } /* Setup the receive mac configuration registers - Packet * Filter control + the enable / disable for packet filter * in the control reg. */ writel(pf_ctrl.value, &adapter->CSRAddress->rxmac.pf_ctrl.value); writel(ctrl.value, &adapter->CSRAddress->rxmac.ctrl.value); } DBG_LEAVE(et131x_dbginfo); return status; }