Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <libusb.h>
- #include <syslog.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include "bootp.h"
- static const u_int8_t gateway[4] = { 192, 168, 0, 1 };
- static const u_int8_t your_ip[4] = { 192, 168, 0, 2 };
- static const u_int8_t BBB_ip[4] = { 192, 168, 0, 3 };
- static const u_int8_t BBB_hwaddr[6] = {12, 13 ,14 ,15 ,16, 17};
- static const u_int8_t magic_cookie[4] = { 99, 130, 83, 99 };
- static const char servername[3] = {'v', 'v', 'u'};
- static const char filename[3] = {'M', 'L', 'O'};
- static const u_int8_t vendor_stuff[] = {
- BOOTP_OPTION_NETMASK, 4, 255, 255, 255, 0,
- BOOTP_OPTION_GATEWAY, 4, 192, 168, 200, 31,
- BOOTP_OPTION_DNS, 8, 198, 235, 216, 110, 204, 101, 251, 1,
- BOOTP_OPTION_HOSTNAME, 3, 'v', 'v', 'u', 'h',
- BOOTP_OPTION_DOMAIN, 7, 'B', 'B', 'B', 'b', 'o', 'o', 't'
- };
- int setup_bootp_packet(const char *servername, const char *filename, bootp_packet *bpp) {
- int vendorlen;
- memset(bpp, 0, sizeof(*bpp));
- bpp->opcode = 2;
- bpp->hw = 1;
- bpp->hwlength = 6;
- bpp->hopcount = 255;
- bpp->xid = htonl(0);
- bpp->secs = htons(0);
- bpp->flags = htons(0);
- memset(&bpp->ciaddr, 0, 4);
- memcpy(&bpp->hwaddr, &BBB_hwaddr, 6);
- memcpy(&bpp->yiaddr, &your_ip, 4);
- memcpy(&bpp->server_ip, &BBB_ip, 4);
- memcpy(&bpp->bootp_gw_ip, &gateway, 4);
- strncpy((char *)&bpp->servername, servername, sizeof(bpp->servername));
- strncpy((char *)&bpp->bootfile, filename, sizeof(bpp->bootfile));
- memcpy(&bpp->vendor, &magic_cookie, 4);
- vendorlen = 4;
- memcpy(((u_int8_t *)&bpp->vendor) + 4, &vendor_stuff,
- sizeof(vendor_stuff));
- vendorlen += sizeof(vendor_stuff);
- bpp->vendor[vendorlen++] = 0xFF;
- return vendorlen;
- }
- int main(int argc, const char * argv[]) {
- bootp_packet *breq = (bootp_packet *)malloc(sizeof(bootp_packet));
- setup_bootp_packet(servername, filename, breq);
- /*unsigned char* address = (unsigned char*)&breq;
- unsigned char *data = (unsigned char*)malloc(64*sizeof(unsigned char));
- int actual;
- libusb_device **devs;
- libusb_device_handle *dev_handle;
- libusb_context *ctx = NULL;
- int r;
- ssize_t cnt;
- r = libusb_init(&ctx);
- if(r < 0) {
- printf("Init error!\n");
- return 1;
- }
- libusb_set_debug(ctx, 3);
- cnt = libusb_get_device_list(ctx, &devs);
- if(cnt < 0) {
- printf("Cannot get device list!\n");
- return 1;
- }
- printf("%zd devices in list!\n",cnt);
- dev_handle = libusb_open_device_with_vid_pid(ctx, 0x0451, 0x6141);
- if(dev_handle == NULL) {
- printf("Cannot open device!\n");
- return 1;
- }
- else printf("Device opened!\n");
- libusb_free_device_list(devs, 1);
- if(libusb_kernel_driver_active(dev_handle, 0) == 1) {
- printf("Kernel has driver!\n");
- if(libusb_detach_kernel_driver(dev_handle, 0) == 0)
- printf("Kernel deattached!\n");
- }
- r = libusb_claim_interface(dev_handle, 0);
- if(r < 0) {
- printf("Cannot Claim Interface!\n");
- return 1;
- }
- printf("Claimed interface!\n");
- r = libusb_bulk_transfer(dev_handle, (129 | LIBUSB_ENDPOINT_IN), data, 64, &actual, 0);
- r = libusb_bulk_transfer(dev_handle, (2 | LIBUSB_ENDPOINT_OUT), address, sizeof(breq), &actual, 0);
- printf("%ld...%d\n",sizeof(breq),actual );
- r = libusb_release_interface(dev_handle, 0);
- if(r!=0) {
- printf("Cannot release interface!\n");
- return 1;
- }
- libusb_close(dev_handle);
- libusb_exit(ctx);
- free(data);*/
- debug_bootp_packet(breq, sizeof(breq));
- free(breq);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment