void cb_dev_found (const char *devName, void *user_data) { neardal_dev *dev; errorCode_t ec; printf("---- NFC Device found\n"); strcpy(DevName,devName); ec = neardal_get_dev_properties(devName, &dev); if (ec == NEARDAL_SUCCESS) { dump_dev(dev); neardal_free_device(dev); } else { printf("Unable to read device properties (error:%d)\n", ec); } main_loop_state = device_found; presence=1; }
int main(int argc, char **argv) { int fd; int ac; isdn_ioctl_struct ioctl_s; isdnloop_cdef newcard; isdnloop_sdef startparm; cmd = strrchr(argv[0], '/'); cmd = (cmd == NULL) ? argv[0] : cmd + 1; if (argc > 1) { if (!strcmp(argv[1], "-d")) { strcpy(ioctl_s.drvid, argv[2]); arg_ofs = 3; } else { ioctl_s.drvid[0] = '\0'; arg_ofs = 1; } } else usage(); ac = argc - (arg_ofs - 1); fd = open("/dev/isdnctrl", O_RDWR); if (fd < 0) { perror(ctrldev); exit(-1); } #ifdef __DEBUGVAR__ if (!strcmp(argv[arg_ofs], "dump")) { char *p; ioctl_s.arg = (ulong) & dbg; if ((ioctl(fd, ISDNLOOP_IOCTL_DEBUGVAR + IIOCDRVCTL, &ioctl_s)) < 0) { perror("ioctl DEBUGVAR"); exit(-1); } close(fd); p = mapmem(dbg.dev, sizeof(icn_dev)); dump_dev((icn_dev *) p); p = mapmem(dbg.card, sizeof(icn_card)); dump_card((icn_card *) p); return 0; } #endif if (!strcmp(argv[arg_ofs], "leased")) { if (ac == 3) { ioctl_s.arg = 0; if ((!strcmp(argv[arg_ofs + 1], "on")) || (!strcmp(argv[arg_ofs + 1], "yes"))) ioctl_s.arg = 1; if ((ioctl(fd, ISDNLOOP_IOCTL_LEASEDCFG + IIOCDRVCTL, &ioctl_s)) < 0) { perror("ioctl LEASEDCFG"); exit(-1); } close(fd); return 0; } } if (!strcmp(argv[arg_ofs], "add")) { if (ac >= 2) { ioctl_s.arg = (unsigned long) &newcard; newcard.id1[0] = 0; strncpy(newcard.id1, argv[arg_ofs + 1], sizeof(newcard.id1) - 1); if ((ioctl(fd, ISDNLOOP_IOCTL_ADDCARD + IIOCDRVCTL, &ioctl_s)) < 0) { perror("ioctl ADDCARD"); exit(-1); } close(fd); return 0; } } if (!strcmp(argv[arg_ofs], "start")) { int needed = 99; if (ac > 2) { if (!(strcmp(argv[arg_ofs + 1], "1tr6"))) { needed = 4; startparm.ptype = ISDN_PTYPE_1TR6; } if (!(strcmp(argv[arg_ofs + 1], "dss1"))) { needed = 6; startparm.ptype = ISDN_PTYPE_EURO; } if (ac >= needed) { strcpy(startparm.num[0], argv[arg_ofs + 2]); if (needed > 4) { strcpy(startparm.num[1], argv[arg_ofs + 3]); strcpy(startparm.num[2], argv[arg_ofs + 4]); } ioctl_s.arg = (unsigned long) &startparm; if (ioctl(fd, ISDNLOOP_IOCTL_STARTUP + IIOCDRVCTL, &ioctl_s) < 0) { perror("\nioctl STARTUP"); exit(-1); } printf("done\n"); close(fd); return 0; } } usage(); } usage(); return 0; }
/* Eth device open */ static int ep93xx_eth_open(struct eth_device *dev, bd_t *bd) { struct ep93xx_priv *priv = GET_PRIV(dev); struct mac_regs *mac = GET_REGS(dev); uchar *mac_addr = dev->enetaddr; int i; debug("+ep93xx_eth_open"); /* Reset the MAC */ ep93xx_mac_reset(dev); /* Reset the descriptor queues' current and end address values */ priv->tx_dq.current = priv->tx_dq.base; priv->tx_dq.end = (priv->tx_dq.base + NUMTXDESC); priv->tx_sq.current = priv->tx_sq.base; priv->tx_sq.end = (priv->tx_sq.base + NUMTXDESC); priv->rx_dq.current = priv->rx_dq.base; priv->rx_dq.end = (priv->rx_dq.base + NUMRXDESC); priv->rx_sq.current = priv->rx_sq.base; priv->rx_sq.end = (priv->rx_sq.base + NUMRXDESC); /* * Set the transmit descriptor and status queues' base address, * current address, and length registers. Set the maximum frame * length and threshold. Enable the transmit descriptor processor. */ writel((uint32_t)priv->tx_dq.base, &mac->txdq.badd); writel((uint32_t)priv->tx_dq.base, &mac->txdq.curadd); writel(sizeof(struct tx_descriptor) * NUMTXDESC, &mac->txdq.blen); writel((uint32_t)priv->tx_sq.base, &mac->txstsq.badd); writel((uint32_t)priv->tx_sq.base, &mac->txstsq.curadd); writel(sizeof(struct tx_status) * NUMTXDESC, &mac->txstsq.blen); writel(0x00040000, &mac->txdthrshld); writel(0x00040000, &mac->txststhrshld); writel((TXSTARTMAX << 0) | (PKTSIZE_ALIGN << 16), &mac->maxfrmlen); writel(BMCTL_TXEN, &mac->bmctl); /* * Set the receive descriptor and status queues' base address, * current address, and length registers. Enable the receive * descriptor processor. */ writel((uint32_t)priv->rx_dq.base, &mac->rxdq.badd); writel((uint32_t)priv->rx_dq.base, &mac->rxdq.curadd); writel(sizeof(struct rx_descriptor) * NUMRXDESC, &mac->rxdq.blen); writel((uint32_t)priv->rx_sq.base, &mac->rxstsq.badd); writel((uint32_t)priv->rx_sq.base, &mac->rxstsq.curadd); writel(sizeof(struct rx_status) * NUMRXDESC, &mac->rxstsq.blen); writel(0x00040000, &mac->rxdthrshld); writel(BMCTL_RXEN, &mac->bmctl); writel(0x00040000, &mac->rxststhrshld); /* Wait until the receive descriptor processor is active */ while (!(readl(&mac->bmsts) & BMSTS_RXACT)) ; /* noop */ /* * Initialize the RX descriptor queue. Clear the TX descriptor queue. * Clear the RX and TX status queues. Enqueue the RX descriptor and * status entries to the MAC. */ for (i = 0; i < NUMRXDESC; i++) { /* set buffer address */ (priv->rx_dq.base + i)->word1 = (uint32_t)NetRxPackets[i]; /* set buffer length, clear buffer index and NSOF */ (priv->rx_dq.base + i)->word2 = PKTSIZE_ALIGN; } memset(priv->tx_dq.base, 0, (sizeof(struct tx_descriptor) * NUMTXDESC)); memset(priv->rx_sq.base, 0, (sizeof(struct rx_status) * NUMRXDESC)); memset(priv->tx_sq.base, 0, (sizeof(struct tx_status) * NUMTXDESC)); writel(NUMRXDESC, &mac->rxdqenq); writel(NUMRXDESC, &mac->rxstsqenq); /* Set the primary MAC address */ writel(AFP_IAPRIMARY, &mac->afp); writel(mac_addr[0] | (mac_addr[1] << 8) | (mac_addr[2] << 16) | (mac_addr[3] << 24), &mac->indad); writel(mac_addr[4] | (mac_addr[5] << 8), &mac->indad_upper); /* Turn on RX and TX */ writel(RXCTL_IA0 | RXCTL_BA | RXCTL_SRXON | RXCTL_RCRCA | RXCTL_MA, &mac->rxctl); writel(TXCTL_STXON, &mac->txctl); /* Dump data structures if we're debugging */ dump_dev(dev); dump_rx_descriptor_queue(dev); dump_rx_status_queue(dev); dump_tx_descriptor_queue(dev); dump_tx_status_queue(dev); debug("-ep93xx_eth_open"); return 1; }
int main(int argc, char **argv) { int option = 0; int domid = -1, bus = -1, device = -1; int vassign = 0, vunassign = 0, attach = 0, detach = 0, list = 0, dump = 0; char *action = NULL; dominfo_t di; usbinfo_t ui; int ret = 0; xs_handle = xs_daemon_open(); if (xs_handle == NULL) { xd_log(LOG_ERR, "Failed to connect to xenstore"); exit(1); } if ((xs_dom0path = xs_get_domain_path(xs_handle, 0)) == NULL) { xd_log(LOG_ERR, "Could not get domain 0 path from XenStore"); exit(1); } while ((option = getopt(argc, argv, "D:b:d:")) != -1) { switch (option) { case 'D': domid = atoi(optarg); if (get_dominfo(domid, &di)) exit(1); break; case 'b': bus = atoi(optarg); break; case 'd': device = atoi(optarg); break; } } if (optind != argc-1) { usage(); } action = argv[optind]; vassign = !strcmp(action, "assign"); vunassign = !strcmp(action, "unassign"); attach = !strcmp(action, "attach"); detach = !strcmp(action, "detach"); list = !strcmp(action, "list"); dump = !strcmp(action, "dump"); if (vassign || vunassign || attach || detach || dump) { if (bus < 0 || device < 0) usage(); if (get_usbinfo(bus, device, &ui)) { if (detach) { /* can proceed detaching without detailed device info, we only need bus & dev num */ } else if (vunassign) { /* no device so nothing to unassign */ exit(0); } else { xd_log(LOG_ERR, "Failed to find device %d:%d", bus, device); exit(1); } } } if (optind == argc) { dump_dev(&ui); return 0; } if (dump) dump_dev(&ui); else if (vassign) ret = vusb_assign(ui.usb_vendor, ui.usb_product, 1); else if (vunassign) ret = vusb_assign(ui.usb_vendor, ui.usb_product, 0); else if (attach) { if (domid < 0) usage(); ret = xenstore_create_usb(&di, &ui); } else if (detach) { if (domid < 0) usage(); ret = xenstore_destroy_usb(&di, &ui); } else if (list) { if (domid < 0) usage(); list_domain_devs(&di); } if (ret) xd_log(LOG_ERR, "Operation failed"); return ret == 0 ? 0 : 1; }