void do_display(int print_flags) { int i; int ret; if ((print_flags & PRINT_FLAG_ALL) != 0) for (i = 1; i <= MAX_RT_DEVICES; i++) { cmd.args.info.ifindex = i; ret = ioctl(f, IOC_RT_IFINFO, &cmd); if (ret == 0) { if (((print_flags & PRINT_FLAG_INACTIVE) != 0) || ((cmd.args.info.flags & IFF_RUNNING) != 0)) print_dev(); } else if (errno != ENODEV) { perror("ioctl"); exit(1); } } else { cmd.args.info.ifindex = 0; ret = ioctl(f, IOC_RT_IFINFO, &cmd); if (ret < 0) { perror("ioctl"); exit(1); } print_dev(); } exit(0); }
Q_MSG *DEV_msgRpt(uint8 type,uint32 timeout) { uint8 err; Q_MSG *msg = NULL; Timer.dev_msg_rpt = timeout / 10 + 1; while(Timer.dev_msg_rpt){ msg = (Q_MSG *)OSQPend(dev_Q_r,50,&err); print_dev("DEV_msgRpt:err=%d,type=%d\r\n",err,type); if(err == OS_NO_ERR && msg->type == type){ print_dev("DEV_msgRpt:type=%d\r\n",type); return msg; } } return NULL; }
void MT_devhopperFlush(void) { uint8 i,j; for(i = 0;i < HP_SUM;i++){ if(stHopperLevel[i].ch == 0){ print_dev("HP_min no=%d,ch=%d\r\n",i,stHopperLevel[i - 1].ch); if(i > 0){ g_hpMinCh = stHopperLevel[i - 1].ch; g_hpNo = i; } break; } } for(i = 0; i < 8;i++){ //print_dev("ratio[%d]\r\n",i); for(j = 0;j < HP_SUM;j++){ //print_dev("ch[%d]=%d\r\n",j,stHopperLevel[j].ch); stMdb.billRato[i].ch[j] = stHopperLevel[j].ch; stMdb.coinRato[i].ch[j] = stHopperLevel[j].ch; } } //DEV_scanRatio(); //ɨÃè ²¢ÑéÖ¤ ¶Ò±Ò±ÈÀý }
void list_devices(libusb_context * ctx) { int r; libusb_device ** devs; ssize_t n = libusb_get_device_list(ctx, &devs); if (n < 0) { std::cerr << std::dec << "get device list fail : " << n << std::endl; exit(n); } std::cout << n << " devices\n\n"; for (int i = 0; i < n; i++) { std::cout << "device[" << i << "] : \n"; print_dev("\t", devs[i]); std::cout << std::endl; } const int RELEASE_REFERENCE_COUNT = 1; libusb_free_device_list(devs, RELEASE_REFERENCE_COUNT); }
static void DEV_reqPoll(void) { uint8 err; Q_MSG *msg; msg = (Q_MSG *)OSQPend(dev_Q_s,2,&err); if(err == OS_NO_ERR){ //ÓÐÇëÇó print_dev("DEV_reqPoll:type=%d\r\n",msg->type); switch(msg->type){ case DEV_ENABLE: DEV_enableRpt(msg); break; case DEV_PAYOUT: DEV_payoutRpt(msg); break; case DEV_HP_PAYOUT: DEV_hpPayoutRpt(msg); break; default:break; } } }
int main(int argc, char **argv) { int c, i; int interval = 1; /* Interval between displays */ int count = 0; /* Number of times to sample */ int write_evts = FALSE; int pos = 0; #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif /* For I18N */ (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); pgmname = basename(argv[0]); if ((kc = kstat_open()) == NULL) { (void) fprintf(stderr, gettext("%s: could not " "open /dev/kstat\n"), pgmname); exit(1); } while ((c = getopt(argc, argv, "e:w:r:ahln")) != EOF) { switch (c) { case 'a': delta = FALSE; break; case 'e': (void) print_evt(); break; case 'h': usage(); break; case 'l': (void) print_dev(argc, argv[argc-1]); break; case 'n': banner = FALSE; break; case 'r': (void) parse_cmd(READ_EVT); break; case 'w': (void) parse_cmd(WRITE_EVT); write_evts = TRUE; break; default: (void) fprintf(stderr, gettext("%s: invalid " "option\n"), pgmname); usage(); break; } } if ((argc == 1) || (dev_list_head == NULL)) usage(); /* * validate remaining operands are numeric. */ pos = optind; while (pos < argc) { if (strisnum(argv[pos]) == 0) { (void) fprintf(stderr, gettext("%s: syntax error\n"), pgmname); usage(); } pos++; } if (optind < argc) { if ((interval = atoi(argv[optind])) == 0) { (void) fprintf(stderr, gettext("%s: invalid " "interval value\n"), pgmname); exit(1); } optind++; if (optind < argc) if ((count = atoi(argv[optind])) <= 0) { (void) fprintf(stderr, gettext("%s: " "invalid iteration value.\n"), pgmname); exit(1); } } set_timer(interval); /* * Set events for the first time. */ if (write_evts == TRUE) setup_evts(); if (count > 0) { for (i = 0; i < count; i++) { if (banner) print_banner(); check_dr_ops(); read_evts(); (void) fflush(stdout); (void) pause(); } } else { for (;;) { if (banner) print_banner(); check_dr_ops(); read_evts(); (void) fflush(stdout); (void) pause(); } } read_evts(); return (0); }
int main(int argc, char** argv) { libusb_device_handle * handle = NULL; libusb_context * ctx = NULL; uint16_t vid = 0x18d1; uint16_t pid = 0x4e22; int r; if (SIG_ERR == signal(SIGINT, &sig_handler)) { std::cerr << "can not catch SIGINT\n"; } signal(SIGTERM, &sig_handler); signal(SIGKILL, &sig_handler); r = libusb_init(&ctx); if (r != LIBUSB_SUCCESS) { std::cerr << "libusb init fail. " << libusb_error_name(r) << std::endl; exit(r); } //////////////////////////////////////////////////////////////////////////////////////////////// // Switch to aoap mode //////////////////////////////////////////////////////////////////////////////////////////////// handle = libusb_open_device_with_vid_pid(ctx, vid, pid); if (handle == NULL) { std::cerr << "open device " << vid << ":" << pid << " error. " << libusb_error_name(errno) << std::endl; // exit(errno); } else { libusb_device * dev = NULL; dev = libusb_get_device(handle); dev = libusb_ref_device(dev); print_dev("", dev); { // 1. Get AOA Protocol on phone if (GetProtocol(handle) == false) { std::cerr << "Get AOA Protocol error\n"; libusb_unref_device(dev); libusb_exit(ctx); exit(-1); } // 2. send accessory information if (SendAccessoryInfos(handle) == false) { std::cerr << "Send Accessory infos error\n"; libusb_unref_device(dev); libusb_exit(ctx); exit(-2); } // 3. send reset command if (SendResetCommand(handle) == false) { std::cerr << "Send Reset command error\n"; libusb_unref_device(dev); libusb_exit(ctx); exit(-3); } } std::cout << "phone reset to aoa mode\n"; libusb_unref_device(dev); } std::cout << std::endl; std::cout << "===========================================================================\n"; // list_devices(ctx); std::cout << "===========================================================================\n"; // open aoa phone pid = 0x2D01; handle = NULL; int cnt = 60; while (handle == NULL) { handle = libusb_open_device_with_vid_pid(ctx, vid, pid); if (handle != NULL) { break; } sleep(1); if (--cnt < 0) { break; } } if (handle == NULL) { std::cerr << "open device " << vid << ":" << pid << " error. " << libusb_error_name(errno) << std::endl; // exit(errno); } else { for (int i = 0; i < 15; i++) { sleep(1); std::cout << "." << std::flush; } std::cout << std::endl; std::cout << "open device " << vid << ":" << pid << " success." << std::endl; libusb_device * dev = NULL; dev = libusb_get_device(handle); dev = libusb_ref_device(dev); print_dev("", dev); std::cout << std::endl; int interface = 0; unsigned char endpoint_in = 0, endpoint_out = 0; GetCommunicationEndpoint(handle, dev, interface, endpoint_in, endpoint_out); std::cout << std::endl; std::cout << "Get interface : " << (int)interface << std::endl; std::cout << "Get input endpoint address : 0x" << std::hex << (int)endpoint_in << std::endl; std::cout << "Get output endpoint address : 0x" << (int)endpoint_out << std::dec << std::endl; // 1. check whether kernel use this device or not int active = libusb_kernel_driver_active(handle, interface); std::cout << "interface [" << interface << "] active = " << active << std::endl; if (active == 1) { r = libusb_detach_kernel_driver(handle, interface); if (r != LIBUSB_SUCCESS) { std::cerr << "detach kernel drive error. " << libusb_error_name(r) << std::endl; } } else if (active != 0) {// 0 means no kernel drive active std::cerr << "query kernel drive active fail. " << libusb_error_name(active) << std::endl; } // 2. claim interface r = libusb_claim_interface(handle, interface); if (r != LIBUSB_SUCCESS) { std::cerr << "claim interface error. " << libusb_error_name(r) << std::endl; } else { std::cout << "claim interface[" << interface << "] success\n"; } { // TODO // communication // int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle, // unsigned char endpoint, unsigned char *data, int length, // int *actual_length, unsigned int timeout); char buf[1024]; memset(buf, 0, sizeof(buf)); const char * info = "USB accessory [Ubuntu 12.04 host]"; //const char * info = "Telenav USB accessory"; //const char * info = "brad.shi"; strncpy(buf, info, sizeof(buf)); int actual_transfer_bytes = 0; int timeout = 1000; r = libusb_bulk_transfer(handle, endpoint_out, (unsigned char*)&buf[0], strlen(buf) + 1, &actual_transfer_bytes, timeout); if (r != LIBUSB_SUCCESS) { std::cerr << "bulk transfer error [hu -> phone]. " << libusb_error_name(r) << std::endl; } else { std::cout << "WOW, bulk transfer success [hu -> phone]. " << actual_transfer_bytes << " bytes transfered." << std::endl; } memset(buf, 0, sizeof(buf)); timeout = 5 * 1000; r = libusb_bulk_transfer(handle, endpoint_in, (unsigned char*)&buf[0], sizeof(buf), &actual_transfer_bytes, timeout); if (r != LIBUSB_SUCCESS) { std::cerr << "bulk transfer error [phone -> hu]. " << libusb_error_name(r) << std::endl; } else { std::cout << "WOW, bulk transfer success [phone -> hu]. " << actual_transfer_bytes << " bytes transfered." << std::endl; std::cout << "RECEIVE : " << buf << std::endl; } } // end communication { // async io const char * msg = "test usb async io."; //char buf[1024]; char * buf; int timeout = 2000; buf = (char*)malloc(strlen(msg) + 1); memset(buf, 0, strlen(msg) + 1); strncpy(buf, msg, strlen(msg)); std::cout << "buf : " << buf << std::endl; std::cout << "strlen(buf) = " << strlen(buf) << std::endl; // char readBuf[1024] = {0}; // if this cause crash issue, declare it as global variable // struct libusb_transfer inTransfer = {0}; // if this cause crash issue, use , answer : this will cause unexpect result // struct libusb_transfer * inTransfer = libusb_alloc_transfer(0); // struct libusb_transfer outTransfer = {0}; struct libusb_transfer * pOutTransfer = libusb_alloc_transfer(0); // should free it by calling libusb_free_transfer(libusb_transfer *) struct libusb_transfer & outTransfer = *pOutTransfer; std::cout << "fill out transfer" << std::endl; libusb_fill_bulk_transfer(&outTransfer // struct libusb_transfer* , handle // libusb_device_handle * , endpoint_out // address of the endpoint where this transfer will be sent , (unsigned char*)&buf[0] // data buffer , strlen(buf) + 1 // length of data buffer , &usbSendComplete // callback fn, libusb_transfer_cb_fn , NULL // user data to pass to callback function , timeout); // timeout for the transfer in milliseconds std::cout << "submit out transfer" << std::endl; r = libusb_submit_transfer(&outTransfer); if (r != LIBUSB_SUCCESS) { std::cout << "r = " << r << ". " << libusb_error_name(r) << std::endl; } std::cout << "fill in transfer" << std::endl; struct libusb_transfer * pInTransfer = libusb_alloc_transfer(0); struct libusb_transfer & inTransfer = *pInTransfer; libusb_fill_bulk_transfer(&inTransfer // struct libusb_transfer * , handle , endpoint_in , (unsigned char*)&readBuf[0] , sizeof(readBuf) - 1 , &usbRecvComplete // callback fn, libusb_transfer_cb_fn , NULL , timeout); std::cout << "submit in transfer" << std::endl; r = libusb_submit_transfer(&inTransfer); if (r != LIBUSB_SUCCESS) { std::cout << "r = " << r << ". " << libusb_error_name(r) << std::endl; } for (int i = 0; i < 10; i++) { struct timeval tv; tv.tv_sec = 1; // seconds tv.tv_usec = 0; // milliseconds ( .1 sec) r = libusb_handle_events_timeout(ctx, &tv); sleep(1); std::cout << '.'; } std::cout << std::endl; // release libusb_transfer std::cout << "LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or cancelled." << std::endl; if (pOutTransfer) { r = libusb_cancel_transfer(pOutTransfer); if (LIBUSB_SUCCESS == r){ std::cout << "pOutTransfer successfully cancelled\n"; } else { std::cerr << "can out transfer error : " << libusb_error_name(r) << std::endl; } libusb_free_transfer(pOutTransfer); pOutTransfer = NULL; } if (pInTransfer) { r = libusb_cancel_transfer(pInTransfer); if (LIBUSB_SUCCESS == r){ std::cout << "pInTransfer successfully cancelled\n"; } else { std::cerr << "can in transfer error : " << libusb_error_name(r) << std::endl; } libusb_free_transfer(pInTransfer); pInTransfer = NULL; } free(buf); } std::cout << "releasing interface..." << std::endl; // -2. release interface r = libusb_release_interface(handle, interface); if (r != LIBUSB_SUCCESS) { std::cerr << "release interface error. " << libusb_error_name(r) << std::endl; } else { std::cout << "release interface[" << interface << "] success\n"; } // ??? reset aoa ??? // SendResetCommand(handle); // libusb_reset_device(handle); GetProtocol(handle); // -1. reactive kernel driver? if (active == 1) { r = libusb_attach_kernel_driver(handle, interface); if (r != LIBUSB_SUCCESS) { std::cerr << "attach kenel drive error. " << libusb_error_name(r) << std::endl; } } libusb_unref_device(dev); } libusb_exit(ctx); std::cout << "===========================================================================\n" << std::flush; cnt = 5; while(g_quit == false) { if (cnt < 0) { std::cout << "extends 60s. quit*\n"; break; } sleep(1); cnt--; } return 0; }
int main(int argc, const char * argv[]) { libusb_device ** devs; int r = libusb_init(NULL); if(r < 0) { fprintf(stderr, "libusb_init() returned error %d\n", r); return r; } ssize_t cnt = libusb_get_device_list(NULL, &devs); if(cnt < 0) { fprintf(stderr, "libusb_get_device_list() returned error %d\n", r); return cnt; } // for(libusb_device ** dev = devs; *dev != NULL; dev++) // print_dev(*dev); libusb_device * lpcdev = find_lpc(devs); if(lpcdev) { printf("Found device:\n"); print_dev(lpcdev); libusb_device_handle * lpchand; r = libusb_open(lpcdev, &lpchand); if(r < 0) { fprintf(stderr, "libusb_open() returned error %d\n", r); exit(r); } r = libusb_set_configuration(lpchand, 1); if(r < 0) { fprintf(stderr, "libusb_set_configuration() returned error %d\n", r); libusb_close(lpchand); exit(r); } int interface = 1; r = libusb_claim_interface(lpchand, interface); if(r < 0) { fprintf(stderr, "libusb_claim_interface() returned error %d\n", r); libusb_close(lpchand); exit(r); } // uint8_t endpoint = 0x82; uint8_t endpoint = 0x02; uint8_t data[256]; char * chdata = (char *)data; int length, actualLength; // data[0] = 100; strcpy(chdata, "USB MESSAGE "); length = 16; r = libusb_bulk_transfer(lpchand, endpoint, data, length, &actualLength, 1000); if(r < 0) { fprintf(stderr, "libusb_bulk_transfer() returned error %d\n", r); libusb_release_interface(lpchand, interface); libusb_close(lpchand); exit(r); } fprintf(stderr, "libusb_bulk_transfer() returned %d\n", r); printf("Bytes transferred: %d\n", actualLength); r = libusb_release_interface(lpchand, interface); if(r < 0) { fprintf(stderr, "libusb_release_interface() returned error %d\n", r); libusb_close(lpchand); exit(r); } libusb_close(lpchand); } else { printf("Device not found\n"); } libusb_free_device_list(devs, 1); libusb_exit(NULL); return EXIT_SUCCESS; }
void MT_devInit(void) { uint8 res,type,i; type = MDB_getCoinAcceptor();//³õʼ»¯Ó²±ÒÆ÷ if(type == COIN_ACCEPTOR_PPLUSE){ LED_showString("CO--"); print_dev("COIN_ACCEPTOR_PPLUSE:init:hightEnable=%d\r\n",stMdb.highEnable); PCOIN_initParallelPluse(stMdb.highEnable); LED_showString("CO-1"); } else if(type == COIN_ACCEPTOR_SPLUSE){ LED_showString("CO--"); print_dev("COIN_ACCEPTOR_SPLUSE:init:hightEnable=%d\r\n",stMdb.highEnable); PCOIN_initSerialPluse(stMdb.highEnable); LED_showString("CO-1"); } msleep(100); type = MDB_getCoinDispenser(); if(type == COIN_DISPENSER_HOPPER){ LED_show("HP--"); HP_init(); msleep(500); for(i = 0;i < HP_SUM;i++){ if(stHopper[i].ch > 0){ LED_show("HP%d-",i + 1); res = HP_send_check(&stHopper[i]); if(res == 1){ LED_show("HP%d%d",i + 1,1); msleep(500); } else{ LED_show("HP%d%d",i + 1,0); msleep(500); } } } MT_devhopperFlush(); } msleep(100); type = MDB_getBillAcceptor(); if(type == BILL_ACCEPTOR_MDB){ stBill.s.status |= BILL_BIT_FAULT; stBill.s.errNo |= BILL_ERR_COM; LED_show("BL--"); for(i = 0;i < 3;i++){ res = billInit(); if(res == 1){ stBill.s.status &= ~BILL_BIT_FAULT; stBill.s.errNo = 0; LED_show("BL-1"); break; } else{ msleep(500); } } if(i >= 3){ LED_show("BL-0"); msleep(1000); } } }
uint8 DEV_payoutRpt(Q_MSG *msg) { uint8 i,n; uint32 amount = 0,changed = 0,remain = 0; uint16 changedCount,payCount,remainPayCount; uint16 hp[HP_SUM] = {0}; ST_CHANGE_RATO *ratio = NULL; if(msg == NULL){return 0;} print_dev("DEV_payoutRpt:b_ratio=%d,c_ratio=%d\r\n",msg->billRatioIndex,msg->coinRatioIndex); MDB_billEnable(0); MDB_coinEnable(0); changed = 0; memset(hp,0,sizeof(uint16) * HP_SUM); remainPayCount = 0; if(msg->billRatioIndex > 0){ //ÓÐÖ½±Ò¶Ò±Ò±ÈÀý ratio = &stMdb.billRato[msg->billRatioIndex - 1]; if(ratio->amount > 0){ n = msg->billAmount / ratio->amount; for(i = 0;i < 8;i++){ payCount = ratio->num[i] * n; if(payCount > 0){ changedCount = HP_payout_by_level(i,payCount,hp); if(changedCount < payCount && g_hpMinCh > 0){ remainPayCount += (stHopperLevel[i].ch / g_hpMinCh) * (payCount - changedCount); } changed += changedCount * ratio->ch[i]; } } } if(remainPayCount > 0 && g_hpNo > 0){ changedCount = HP_payout_by_level(g_hpNo - 1,remainPayCount,hp); changed += changedCount * g_hpMinCh; if(changedCount < remainPayCount){ dev_msg_r[dev_in_r].iou = (remainPayCount - changedCount) * g_hpMinCh; } else{ dev_msg_r[dev_in_r].iou = 0; } } else{ dev_msg_r[dev_in_r].iou = 0; } } else if(msg->coinRatioIndex > 0){ ratio = &stMdb.coinRato[msg->coinRatioIndex - 1]; if(ratio->amount > 0){ n = msg->coinAmount / ratio->amount; for(i = 0;i < 8;i++){ payCount = ratio->num[i] * n; if(payCount > 0){ changedCount = HP_payout_by_level(i,ratio->num[i] * n,hp); if(changedCount < payCount && g_hpMinCh > 0){ remainPayCount += (stHopperLevel[i].ch / g_hpMinCh) * (payCount - changedCount); } changed += changedCount * ratio->ch[i]; } } } if(remainPayCount > 0 && g_hpNo > 0){ changedCount = HP_payout_by_level(g_hpNo - 1,remainPayCount,hp); changed += changedCount * g_hpMinCh; if(changedCount < remainPayCount){ dev_msg_r[dev_in_r].iou = (remainPayCount - changedCount) * g_hpMinCh; } else{ dev_msg_r[dev_in_r].iou = 0; } } else{ dev_msg_r[dev_in_r].iou = 0; } } else{ amount = msg->billAmount + msg->coinAmount; changed += HP_payout(amount - changed,hp); if(amount > changed){ remain = amount - changed; dev_msg_r[dev_in_r].iou = remain; } else{ dev_msg_r[dev_in_r].iou = 0; } } dev_msg_r[dev_in_r].billAmount = msg->billAmount; dev_msg_r[dev_in_r].coinAmount = msg->coinAmount; dev_msg_r[dev_in_r].coinChanged = changed; for(i = 0;i < HP_SUM;i++){ dev_msg_r[dev_in_r].hp[i] = hp[i]; } //¿Û¿î ¿ÛÍê remain = MDB_billCost(msg->billAmount + msg->coinAmount); print_dev("DEV_payoutRpt:remain=%d\r\n",remain); remain = MDB_coinCost(remain); return DEV_msg_rpt(DEV_PAYOUT); }
static int res_pd_line(struct rd *rd, const char *name, int idx, struct nlattr **nla_line) { uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0; char *comm = NULL; uint32_t ctxn = 0; uint32_t pid = 0; uint32_t pdn = 0; uint64_t users; if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) local_dma_lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_is_filtered_attr(rd, "users", users, nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) unsafe_global_rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_is_filtered_attr(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); if (rd_is_filtered_attr(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]); if (rd_is_filtered_attr(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]); print_key(rd, "local_dma_lkey", local_dma_lkey, nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); res_print_uint(rd, "users", users, nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); print_key(rd, "unsafe_global_rkey", unsafe_global_rkey, nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); print_comm(rd, comm, nla_line); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); return MNL_CB_OK; }
static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_PD]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_PD]; mnl_attr_for_each_nested(nla_entry, nla_table) { uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0; struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; char *comm = NULL; uint32_t pid = 0; uint64_t users; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) local_dma_lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_check_is_filtered(rd, "users", users)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) unsafe_global_rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) print_key(rd, "local_dma_lkey", local_dma_lkey); print_users(rd, users); if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) print_key(rd, "unsafe_global_rkey", unsafe_global_rkey); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); }
static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_MR]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_MR]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; uint32_t rkey = 0, lkey = 0; uint64_t iova = 0, mrlen; char *comm = NULL; uint32_t pid = 0; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) iova = mnl_attr_get_u64( nla_line[RDMA_NLDEV_ATTR_RES_IOVA]); mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]); if (rd_check_is_filtered(rd, "mrlen", mrlen)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) print_key(rd, "rkey", rkey); if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) print_key(rd, "lkey", lkey); if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) print_iova(rd, iova); print_mrlen(rd, mrlen); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }
static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_CQ]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; char *comm = NULL; uint32_t pid = 0; uint8_t poll_ctx = 0; uint64_t users; uint32_t cqe; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_check_is_filtered(rd, "users", users)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { poll_ctx = mnl_attr_get_u8( nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); if (rd_check_is_string_filtered(rd, "poll-ctx", poll_ctx_to_str(poll_ctx))) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); print_cqe(rd, cqe); print_users(rd, users); if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) print_poll_ctx(rd, poll_ctx); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }