static int per_event_excludes(void)
{
	struct event *e, events[4];
	char *platform;
	int i;

	platform = (char *)get_auxv_entry(AT_BASE_PLATFORM);
	FAIL_IF(!platform);
	SKIP_IF(strcmp(platform, "power8") != 0);

	/*
	 * We need to create the events disabled, otherwise the running/enabled
	 * counts don't match up.
	 */
	e = &events[0];
	event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS,
			PERF_TYPE_HARDWARE, "instructions");
	e->attr.disabled = 1;

	e = &events[1];
	event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS,
			PERF_TYPE_HARDWARE, "instructions(k)");
	e->attr.disabled = 1;
	e->attr.exclude_user = 1;
	e->attr.exclude_hv = 1;

	e = &events[2];
	event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS,
			PERF_TYPE_HARDWARE, "instructions(h)");
	e->attr.disabled = 1;
	e->attr.exclude_user = 1;
	e->attr.exclude_kernel = 1;

	e = &events[3];
	event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS,
			PERF_TYPE_HARDWARE, "instructions(u)");
	e->attr.disabled = 1;
	e->attr.exclude_hv = 1;
	e->attr.exclude_kernel = 1;

	FAIL_IF(event_open(&events[0]));

	/*
	 * The open here will fail if we don't have per event exclude support,
	 * because the second event has an incompatible set of exclude settings
	 * and we're asking for the events to be in a group.
	 */
	for (i = 1; i < 4; i++)
		FAIL_IF(event_open_with_group(&events[i], events[0].fd));

	/*
	 * Even though the above will fail without per-event excludes we keep
	 * testing in order to be thorough.
	 */
	prctl(PR_TASK_PERF_EVENTS_ENABLE);

	/* Spin for a while */
	for (i = 0; i < INT_MAX; i++)
		asm volatile("" : : : "memory");

	prctl(PR_TASK_PERF_EVENTS_DISABLE);

	for (i = 0; i < 4; i++) {
		FAIL_IF(event_read(&events[i]));
		event_report(&events[i]);
	}

	/*
	 * We should see that all events have enabled == running. That
	 * shows that they were all on the PMU at once.
	 */
	for (i = 0; i < 4; i++)
		FAIL_IF(events[i].result.running != events[i].result.enabled);

	/*
	 * We can also check that the result for instructions is >= all the
	 * other counts. That's because it is counting all instructions while
	 * the others are counting a subset.
	 */
	for (i = 1; i < 4; i++)
		FAIL_IF(events[0].result.value < events[i].result.value);

	for (i = 0; i < 4; i++)
		event_close(&events[i]);

	return 0;
}
uint32_t
process_diagfw_msg(uint8_t *datap, uint16_t len, uint32_t optionflag,
      FILE *log_out, int32_t *record, int32_t max_records, int32_t version,
      int sock_fd)
{
    uint32_t count = 0, index = 0;
    uint32_t timestamp = 0;
    uint32_t diagid = 0, id = 0;
    uint32_t moduleid = 0, res = 0;
    uint32_t num_buf = 0, payloadlen = 0;
    uint16_t vdevid = 0, vdevlevel = 0;
    uint16_t numargs = 0;
    uint32_t *buffer;
    uint32_t header1 = 0, header2 = 0;
    int32_t  lrecord = 0;
    char *payload;
    char buf[BUF_SIZ], payload_buf[BUF_SIZ];
    char *start = buf;
    int32_t hashInd = 0, i =0, j =0;
    diag_entry *entry = NULL;
    int ret = 0, total_dump_len = 0;
    uint8_t *debugp = datap;
    char dump_buffer[BUF_SIZ];

    if (optionflag & DEBUG_FLAG) {
        memset(dump_buffer, 0, sizeof(dump_buffer));
        debug_printf("process_diagfw_msg hex dump start len %d", len);
        for (i = 0; i < len; i++) {
             ret = snprintf(dump_buffer + j, BUF_SIZ - j, "0x%x ", debugp[i]);
             j += ret;
             if (!(i % 16) && (i!=0)) {
                total_dump_len += 16;
                debug_printf("%s", dump_buffer);
                memset(dump_buffer, 0, sizeof(dump_buffer));
                j = 0;
             }
        }
        if (total_dump_len != len)
           debug_printf("%s", dump_buffer);
        debug_printf("process_diagfw_msg hex dump end");
    }

    if (!gisdiag_init) {
       /* If cnss_diag is started if WIFI already ON,
        * then turn on event not received hence
        * before throwing out error initialize again
        */
        diag_initialize(sock_fd, optionflag);
        if (!gisdiag_init) {
            diag_printf("**ERROR** Diag not Initialized",
                          0, 4, optionflag, 0, NULL);
            return -1;
        }

    }
    buffer = (uint32_t *)datap  ;
    buffer ++; /* increment 1 to skip dropped */
    num_buf = len - 4;
    debug_printf("\n --%s-- %d\n", __FUNCTION__, optionflag);

    while (num_buf  > count) {

        header1 = *(buffer + index);
        header2 = *(buffer + 1 + index);
        payload = (char *)(buffer + 2 + index);
        diagid  = DIAG_GET_TYPE(header1);
        timestamp = DIAG_GET_TIME_STAMP(header1);
        payloadlen = 0;
        debug_printf("\n diagid = %d  timestamp = %d"
                    " header1 = %x heade2 = %x\n",
                     diagid,  timestamp, header1, header2);
        switch (diagid) {
        case WLAN_DIAG_TYPE_EVENT:
        {
            id = DIAG_GET_ID(header2);
            payloadlen = DIAG_GET_PAYLEN16(header2);
            debug_printf("DIAG_TYPE_FW_EVENT: id = %d"
                         " payloadlen = %d \n", id, payloadlen);
            if (optionflag & QXDM_FLAG) {
                if (payloadlen)
                    event_report_payload(id, payloadlen, payload);
                else
                    event_report(id);
             }
        }
        break;
        case WLAN_DIAG_TYPE_LOG:
        {
            id = DIAG_GET_ID(header2);
            payloadlen = DIAG_GET_PAYLEN16(header2);
            debug_printf("DIAG_TYPE_FW_LOG: id = %d"
                         " payloadlen = %d \n", id,  payloadlen);
            if (optionflag & QXDM_FLAG) {
                /* Allocate a log buffer */
                uint8_t *logbuff = (uint8_t*) log_alloc(id,
                                    sizeof(log_hdr_type)+payloadlen);
                if ( logbuff != NULL ) {
                    /* Copy the log data */
                    memcpy(logbuff + sizeof(log_hdr_type), payload,
                              payloadlen);
                    /* Commit the log buffer */
                    log_commit(logbuff);
                }
                else
                    debug_printf("log_alloc failed for len = %d ", payloadlen);
            }
        }
        break;
        case WLAN_DIAG_TYPE_MSG:
        {
            id = DIAG_GET_ID(header2);
            payloadlen = DIAG_GET_PAYLEN(header2);
            vdevid = DIAG_GET_VDEVID(header2);
            vdevlevel = DIAG_GET_VDEVLEVEL(header2);
            memset(buf, 0, BUF_SIZ);
            memset(payload_buf, 0, BUF_SIZ);
            debug_printf(" DIAG_TYPE_FW_DEBUG_MSG: "
                   " vdevid %d vdevlevel %d payloadlen = %d id = %d\n",
                                  vdevid, vdevlevel, payloadlen, id);
            if (gdiag_header->file_version != version) {
                snprintf(buf, BUF_SIZ, "**ERROR**"
                " Data.msc Version %d doesn't match"
                " with Firmware version %d id = %d",
                gdiag_header->file_version, version, id);
                diag_printf(buf, 0, 4, optionflag, 0, NULL);
                break;
            }
            entry = diag_find_by_id(id);
            if (entry) {
                if ((payloadlen > 0) && (entry->format && entry->pack)) {
                    debug_printf("entry->format = %s pack = %s\n",
                                    entry->format, entry->pack);
                    if (payloadlen < BUF_SIZ)
                        memcpy(payload_buf, payload, payloadlen);
                    else
                        memcpy(payload_buf, payload, BUF_SIZ);
                    /* Sending with BUF_SIZ to pack_printf
                     * because some times payloadlen received
                     * doesnt match with the pack specifier, in
                     * that case just print the zero
                     */
                    entry->msg_len = BUF_SIZ;
                    entry->msg = payload_buf;
                    start = buf;
                    pack_printf(
                             dbg_write_char,
                             &start,
                             start + sizeof(buf),
                             entry->format,
                             entry->pack,
                             (uint8_t*)entry->msg,
                             entry->msg_len
                              );
                }
                else if (entry->format)
                    strlcpy(buf, entry->format, strlen(entry->format));

                debug_printf("\n buf = %s \n", buf);
                if (optionflag & LOGFILE_FLAG)  {
                    lrecord = *record;
                    lrecord++;
                    if (!((optionflag & SILENT_FLAG) == SILENT_FLAG))
                        printf("%d: %s\n", lrecord, buf);

                    res = diag_printf(
                         buf, vdevid, vdevlevel, optionflag, timestamp, log_out
                              );
                    //fseek(log_out, lrecord * res, SEEK_SET);
                    if (lrecord == max_records) {
                        lrecord = 0;
                        fseek(log_out, lrecord * res, SEEK_SET);
                    }
                    *record = lrecord;
                }
                if (optionflag & (CONSOLE_FLAG | QXDM_FLAG))
                    diag_printf(
                         buf, vdevid, vdevlevel, optionflag, timestamp, NULL
                              );
            }
            else {
                switch (id) {
                case DIAG_WLAN_MODULE_STA_PWRSAVE:
                case DIAG_WLAN_MODULE_WAL:
                case DIAG_NAN_MODULE_ID:
                case DIAG_WLAN_MODULE_IBSS_PWRSAVE:
                    if (!diag_msg_handler(id, payload, vdevid, timestamp)) {
                        snprintf(buf, BUF_SIZ,
                            "****WARNING****, undefined moduleid = %d no t"
                            " found", moduleid);
                        diag_printf(buf, 0, 4, optionflag, timestamp, NULL);
                    }
                break;
                default:
                    snprintf(buf, BUF_SIZ,
                             "****WARNING****, FWMSG ID %d not found", id);
                    diag_printf(buf, 0, 4, optionflag, timestamp, NULL);
                    printf( "NOT found id = %d\n", id);
                }
            }
        }
        break;
        default:
            diag_printf(" ****WARNING**** WRONG DIAG ID", 0,
                      4, optionflag, timestamp, NULL);
        return 0;
        }
        count  += payloadlen + 8;
        index = count >> 2;
        debug_printf("Loope end:id = %d  payloadlen = %d count = %d index = %d\n",
                    id,  payloadlen,  count, index);
    }

    return (0);
}
Exemple #3
0
Fichier : IP.C Projet : barmi/tcpip
void
rcv_icmp()
{
	struct TCB *tp;
	struct BUFFER *rbp;
	unsigned short icmp_size, i;
	unsigned char *rd;

	//rprintf("[ICMP_R]");
	//print_packet(ICMP_P, 0);
	statistics.icmpInMsgs++;
	icmp_size = ntohs(IP_P->total_len) - IP_HLEN;	//  ICMP Packet size 
	if (checksum(&(ICMP_P->packet_type), icmp_size)) {
		//rprintf("[ICMP CHKSUM]");
		statistics.icmpInErrors++;
		return;
	}
	switch (ICMP_P->packet_type) {
	   case ECHO_REQUEST :	/* Incomming Request */
		statistics.icmpInEchos++;
		//rprintf("[ICMP ECHO_REQUEST]");
		copy_hw_addr(ETH_P->destination, ETH_P->source);
		copy_hw_addr(ETH_P->source, ETH_STUB(tcb)->source);
		IP_P->destination = IP_P->source;
		IP_P->source = tcpipcfg.c_myip;
		ICMP_P->packet_type = ECHO_REPLY;
		ICMP_P->checksum = 0;
		ICMP_P->checksum = checksum(&(ICMP_P->packet_type), icmp_size);
		//rprintf("ECHO REPLY");
		snd_ip(IP_P, icmp_size);
		break;
	   case ECHO_REPLY :		/* Echo Backed Data */
		//rprintf("ICMP REPLY");
		statistics.icmpInEchoReps++;
		for (tp = tcb, i = 0; i < num_socket ; i++, tp++) {
			if (IP_STUB(tp)->transport != IPPROTO_ICMP)
				continue;
			if (IP_STUB(tp)->destination == IP_P->source) {
				if (icmp_size > MAX_BUFSIZE)
					icmp_size = MAX_BUFSIZE;
				if (!(rbp = get_dgram_buf(tp, icmp_size)))
					break;
				//rprintf("[%d:%04X]", i, rbp);
				rbp->r_count = icmp_size;
				rbp->r_ip = IP_P->source;
				copy_mem(_DS, (unsigned)(rbp->data), _DS, (unsigned)ICMP_P + IP_PLEN, icmp_size);
				event_report(tp, IEVENT_READ, data_avail(tp));
				//rprintf("DATA COPYED");
			}
		}
		break;
	   case GATEWAY_REDIRECT :	/* ICMP Redirect */
		statistics.icmpInRedirects++;
		//rprintf("ICMP New Gateway : %08lX", GATE_P->new_gateway);
		// Find channels that uses the former
		// check open, TCB_ARP_ED, TCB_ECHO_ING | SYN_SENT, destination, d_port
		for (tp = tcb, i = 0; i < num_socket; i++, tp++) {
			if (!(IP_STUB(tp)->transport) || !(tp->status & TCB_ARP_ED))
				continue;
			if ((IP_STUB(tp)->destination == E_IP->destination) &&
			    (arp_target(tp) == IP_P->source)) {
				tcpipcfg.c_defgw = GATE_P->new_gateway;
				tp->timeout_count = 1;
				tp->syn_fin_timer = 0;
				clr_status(tp, TCB_ARP_ED);
				start_arp(tp, IP_STUB(tp)->destination);
			}
		}
		break;
	   case DEST_UNREACHABLE :	/* ICMP Destination Unreachable */
		statistics.icmpInDestUnreachs++;
		//rprintf("[Dest Unreach: %08lX(%d) from %08lX code:%d]", E_IP->destination, ntohs(E_TCP->destination), IP_P->source, ICMP_P->opcode);
		for (tp = tcb, i = 0; i < num_socket; i++, tp++) {
			if (!(IP_STUB(tp)->transport) || !(tp->status & TCB_ARP_ED))
				continue;
			if (IP_STUB(tp)->destination == E_IP->destination) {
				if (IP_STUB(tp)->transport == IPPROTO_TCP) {
					statistics.tcpAttemptFails++;
					clean_it(tp, 0);
				}
				if (ICMP_P->opcode == ICMP_NETUNREACH) {
					tp->last_error = ENETUNREACH;
				} else {
					tp->last_error = EHOSTUNREACH;
				}
			}
		}
		break;
	   default :
		//rprintf("ICMP UNKNOWN");
		//rprintf(" ERROR Type:%02X OPcode:%02X 1st:%04X 2nd:%d ",
		//	ICMP_P->packet_type,ICMP_P->opcode,ECHO_P->identification,ECHO_P->sequence);
		//rprintf("from:%08lX\n", IP_P->source);
		statistics.icmpInErrors++;
	}
leave:
	;
}
/*
 * Process FW debug, FW event and FW log messages
 * Read the payload and process accordingly.
 *
 */
void process_cnss_diag_msg(tAniNlHdr *wnl)
{
    uint8_t *dbgbuf;
    uint8_t *eventbuf = (uint8_t *)NLMSG_DATA(wnl);
    uint16_t diag_type = 0;
    uint32_t event_id = 0;
    uint16_t length = 0;
    struct dbglog_slot *slot;
    uint32_t dropped = 0;

    dbgbuf = eventbuf;

    diag_type = *(uint16_t *)eventbuf;
    eventbuf += sizeof(uint16_t);

    length = *(uint16_t *)eventbuf;
    eventbuf += sizeof(uint16_t);

    if (wnl->nlh.nlmsg_type == WLAN_NL_MSG_CNSS_HOST_MSG
        && (wnl->wmsg.type == ANI_NL_MSG_LOG_HOST_MSG_TYPE)) {
          process_cnss_host_message(wnl, optionflag, log_out, &record, max_records);
    } else if (wnl->nlh.nlmsg_type == WLAN_NL_MSG_CNSS_HOST_EVENT_LOG
        && (wnl->wmsg.type == ANI_NL_MSG_LOG_HOST_EVENT_LOG_TYPE)) {
        process_cnss_host_diag_events_log((char *)((char *)&wnl->wmsg.length
        + sizeof(wnl->wmsg.length)), optionflag);
    } else {
        if (diag_type == DIAG_TYPE_FW_EVENT) {
            eventbuf += sizeof(uint32_t);
            event_id = *(uint32_t *)eventbuf;
            eventbuf += sizeof(uint32_t);
            if (optionflag & QXDM_FLAG) {
                if (length)
                    event_report_payload(event_id, length, eventbuf);
                else
                    event_report(event_id);
            }
        } else if (diag_type == DIAG_TYPE_FW_LOG) {
           /* Do nothing for now */
        } else if (diag_type == DIAG_TYPE_FW_DEBUG_MSG) {
            slot =(struct dbglog_slot *)dbgbuf;
            length = get_le32((uint8_t *)&slot->length);
            dropped = get_le32((uint8_t *)&slot->dropped);
            if (optionflag & LOGFILE_FLAG)
                process_cnss_log_file(dbgbuf);
            else if (optionflag & (CONSOLE_FLAG | QXDM_FLAG))
                dbglog_parse_debug_logs(&slot->payload[0], length, dropped);
        } else if (diag_type == DIAG_TYPE_FW_MSG) {
            uint32_t version = 0;
            slot = (struct dbglog_slot *)dbgbuf;
            length = get_32((uint8_t *)&slot->length);
            version = get_le32((uint8_t *)&slot->dropped);
            process_diagfw_msg(&slot->payload[0], length, optionflag, log_out,
                               &record, max_records, version, sock_fd);
        } else if (diag_type == DIAG_TYPE_HOST_MSG) {
            slot = (struct dbglog_slot *)dbgbuf;
            length = get_32((uint8_t *)&slot->length);
            process_diaghost_msg(slot->payload, length);
        } else {
           /* Do nothing for now */
        }
    }

}