L2CAP packetgenerator

/*
* L2CAP packetgenerator
*
* By Bastian Ballmann
* http://www.datenterrorist.de
* Last update: 04.02.2007
*
* Some code borrowed from bss – thx 2 Pierre
*
* License: GPLv3
*/

// Includes
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>

// Functions
void usage(void);

// MAIN PART
int main(int argc, char *argv[])
{
l2cap_cmd_hdr *cmd; // struct detailed in kernel_source/include/net/bluetooth/l2cap.h
struct sockaddr_l2 laddr, raddr;
struct hci_dev_info di;
char *buf, *remote_address = NULL;
char dummy_payload[] = “greets from ccc easterhegg 2007”;
char *payload = dummy_payload;
int sock, c, i;
int l2_code = 0x08;
int l2_ident = 23;
int l2_hsize = 42;

// Get params
while ((c = getopt (argc, argv, “a:c:i:p:s:”)) != -1)
{
switch (c)
{
case ‘a’:
remote_address = optarg;
break;

case ‘c’:
l2_code = atoi(optarg);
break;

case ‘i’:
l2_ident = atoi(optarg);
break;

case ‘p’:
payload = (char *)optarg;
break;

case ‘s’:
l2_hsize = atoi(optarg);
break;

default:
usage();
break;
}
}

if(remote_address == NULL)
{
printf(“>>> I need at least a remote btaddr…\n\n”);
usage();
exit(EXIT_FAILURE);
}

if(l2_hsize == 42)
{
l2_hsize = strlen(payload);
}

// Get local device info
if(hci_devinfo(0, &di) code = l2_code;
cmd->ident = l2_ident;
cmd->len = htobs(l2_hsize);

/* Copy payload after l2cap header */
strncpy((buf + L2CAP_CMD_HDR_SIZE), payload, strlen(payload));

/* Throw the packet into the air */
if(send(sock, buf, L2CAP_CMD_HDR_SIZE + strlen(payload), 0) -c -i -p -s \n”);
printf(“L2CAP command codes:\n”);
printf(“L2CAP_COMMAND_REJ 0x01\n”);
printf(“L2CAP_CONN_REQ 0x02\n”);
printf(“L2CAP_CONN_RSP 0x03\n”);
printf(“L2CAP_CONF_REQ 0x04\n”);
printf(“L2CAP_CONF_RSP 0x05\n”);
printf(“L2CAP_DISCONN_REQ 0x06\n”);
printf(“L2CAP_DISCONN_RSP 0x07\n”);
printf(“L2CAP_ECHO_REQ 0x08\n”);
printf(“L2CAP_ECHO_RSP 0x09\n”);
printf(“L2CAP_INFO_REQ 0x0a\n”);
printf(“L2CAP_INFO_RSP 0x0b\n”);
exit(EXIT_SUCCESS);
}

Advertisements

~ by Balle on July 7, 2007.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: