<commit_before>/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2011-2012  Intel Corporation
 *  Copyright (C) 2004-2010  <NAME> <<EMAIL>>
 *
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>

#include "monitor/mainloop.h"
#include "monitor/bt.h"

#include "amp.h"

#define le16_to_cpu(val) (val)
#define le32_to_cpu(val) (val)
#define cpu_to_le16(val) (val)
#define cpu_to_le32(val) (val)

#define PHY_MODE_IDLE		0x00
#define PHY_MODE_INITIATOR	0x01
#define PHY_MODE_ACCEPTOR	0x02

#define MAX_ASSOC_LEN	672

struct bt_amp {
	volatile int ref_count;
	int vhci_fd;

	char phylink_path[32];
	int phylink_fd;

	uint8_t  event_mask[16];
	uint16_t manufacturer;
	uint8_t  commands[64];
	uint8_t  features[8];

	uint8_t  amp_status;
	uint8_t  amp_type;
	uint8_t  local_assoc[MAX_ASSOC_LEN];
	uint16_t local_assoc_len;
	uint8_t  remote_assoc[MAX_ASSOC_LEN];
	uint16_t remote_assoc_len;

	uint8_t  phy_mode;
	uint8_t  phy_handle;
	uint16_t logic_handle;
};

static void reset_defaults(struct bt_amp *amp)
{
	memset(amp->event_mask, 0, sizeof(amp->event_mask));
	amp->event_mask[1] |= 0x20;	/* Command Complete */
	amp->event_mask[1] |= 0x40;	/* Command Status */
	amp->event_mask[1] |= 0x80;	/* Hardware Error */
	amp->event_mask[2] |= 0x01;	/* Flush Occurred */
	amp->event_mask[2] |= 0x04;	/* Number of Completed Packets */
	amp->event_mask[3] |= 0x02;	/* Data Buffer Overflow */
	amp->event_mask[3] |= 0x20;	/* QoS Violation */
	amp->event_mask[7] |= 0x01;	/* Enhanced Flush Complete */

	amp->event_mask[8] |= 0x01;	/* Physical Link Complete */
	amp->event_mask[8] |= 0x02;	/* Channel Selected */
	amp->event_mask[8] |= 0x04;	/* Disconnection Physical Link Complete */
	amp->event_mask[8] |= 0x08;	/* Physical Link Loss Early Warning */
	amp->event_mask[8] |= 0x10;	/* Physical Link Recovery */
	amp->event_mask[8] |= 0x20;	/* Logical Link Complete */
	amp->event_mask[8] |= 0x40;	/* Disconection Logical Link Complete */
	amp->event_mask[8] |= 0x80;	/* Flow Specification Modify Complete */
	amp->event_mask[9] |= 0x01;	/* Number of Completed Data Blocks */
	amp->event_mask[9] |= 0x02;	/* AMP Start Test */
	amp->event_mask[9] |= 0x04;	/* AMP Test End */
	amp->event_mask[9] |= 0x08;	/* AMP Receiver Report */
	amp->event_mask[9] |= 0x10;	/* Short Range Mode Change Complete */
	amp->event_mask[9] |= 0x20;	/* AMP Status Change */

	amp->manufacturer = 0x003f;	/* Bluetooth SIG (63) */

	memset(amp->commands, 0, sizeof(amp->commands));
	amp->commands[5]  |= 0x40;	/* Set Event Mask */
	amp->commands[5]  |= 0x80;	/* Reset */
	//amp->commands[6]  |= 0x01;	/* Set Event Filter */
	//amp->commands[7]  |= 0x04;	/* Read Connection Accept Timeout */
	//amp->commands[7]  |= 0x08;	/* Write Connection Accept Timeout */
	//amp->commands[10] |= 0x80;	/* Host Number of Completed Packets */
	//amp->commands[11] |= 0x01;	/* Read Link Supervision Timeout */
	//amp->commands[11] |= 0x02;	/* Write Link Supervision Timeout */
	amp->commands[14] |= 0x08;	/* Read Local Version Information */
	amp->commands[14] |= 0x10;	/* Read Local Supported Commands */
	amp->commands[14] |= 0x20;	/* Read Local Supported Features */
	amp->commands[14] |= 0x80;	/* Read Buffer Size */
	//amp->commands[15] |= 0x04;	/* Read Failed Contact Counter */
	//amp->commands[15] |= 0x08;	/* Reset Failed Contact Counter */
	//amp->commands[15] |= 0x10;	/* Read Link Quality */
	//amp->commands[15] |= 0x20;	/* Read RSSI */
	//amp->commands[16] |= 0x04;	/* Enable Device Under Test Mode */
	//amp->commands[19] |= 0x40;	/* Enhanced Flush */

	amp->commands[21] |= 0x01;	/* Create Physical Link */
	amp->commands[21] |= 0x02;	/* Accept Physical Link */
	amp->commands[21] |= 0x04;	/* Disconnect Phyiscal Link */
	amp->commands[21] |= 0x08;	/* Create Logical Link */
	amp->commands[21] |= 0x10;	/* Accept Logical Link */
	amp->commands[21] |= 0x20;	/* Disconnect Logical Link */
	amp->commands[21] |= 0x40;	/* Logical Link Cancel */
	//amp->commands[21] |= 0x80;	/* Flow Specification Modify */
	//amp->commands[22] |= 0x01;	/* Read Logical Link Accept Timeout */
	//amp->commands[22] |= 0x02;	/* Write Logical Link Accept Timeout */
	amp->commands[22] |= 0x04;	/* Set Event Mask Page 2 */
	amp->commands[22] |= 0x08;	/* Read Location Data */
	amp->commands[22] |= 0x10;	/* Write Location Data */
	amp->commands[22] |= 0x20;	/* Read Local AMP Info */
	amp->commands[22] |= 0x40;	/* Read Local AMP ASSOC */
	amp->commands[22] |= 0x80;	/* Write Remote AMP ASSOC */
	amp->commands[23] |= 0x01;	/* Read Flow Control Mode */
	amp->commands[23] |= 0x02;	/* Write Flow Control Mode */
	amp->commands[23] |= 0x04;	/* Read Data Block Size */
	//amp->commands[23] |= 0x20;	/* Enable AMP Receiver Reports */
	//amp->commands[23] |= 0x40;	/* AMP Test End */
	//amp->commands[23] |= 0x80;	/* AMP Test */
	//amp->commands[24] |= 0x04;	/* Read Best Effort Flush Timeout */
	//amp->commands[24] |= 0x08;	/* Write Best Effort Flush Timeout */
	//amp->commands[24] |= 0x10;	/* Short Range Mode */

	memset(amp->features, 0, sizeof(amp->features));

	amp->amp_status = 0x01;		/* Used for Bluetooth only */
	amp->amp_type = 0x42;		/* Fake virtual AMP type */

	memset(amp->local_assoc, 0, sizeof(amp->local_assoc));
	amp->local_assoc_len = 0;

	memset(amp->remote_assoc, 0, sizeof(amp->remote_assoc));
	amp->remote_assoc_len = 0;

	amp->phy_mode = PHY_MODE_IDLE;
	amp->phy_handle = 0x00;		/* Invalid physical link handle */
	amp->logic_handle = 0x0000;
}

static void send_packet(struct bt_amp *amp, const void *data, uint16_t len)
{
	write(amp->vhci_fd, data, len);
}
<commit_msg>emulator: Fix AMP emulation build error<commit_after>/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2011-2012  Intel Corporation
 *  Copyright (C) 2004-2010  <NAME> <<EMAIL>>
 *
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>

#include "monitor/mainloop.h"
#include "monitor/bt.h"

#include "amp.h"

#define le16_to_cpu(val) (val)
#define le32_to_cpu(val) (val)
#define cpu_to_le16(val) (val)
#define cpu_to_le32(val) (val)

#define PHY_MODE_IDLE		0x00
#define PHY_MODE_INITIATOR	0x01
#define PHY_MODE_ACCEPTOR	0x02

#define MAX_ASSOC_LEN	672

struct bt_amp {
	volatile int ref_count;
	int vhci_fd;

	char phylink_path[32];
	int phylink_fd;

	uint8_t  event_mask[16];
	uint16_t manufacturer;
	uint8_t  commands[64];
	uint8_t  features[8];

	uint8_t  amp_status;
	uint8_t  amp_type;
	uint8_t  local_assoc[MAX_ASSOC_LEN];
	uint16_t local_assoc_len;
	uint8_t  remote_assoc[MAX_ASSOC_LEN];
	uint16_t remote_assoc_len;

	uint8_t  phy_mode;
	uint8_t  phy_handle;
	uint16_t logic_handle;
};

static void reset_defaults(struct bt_amp *amp)
{
	memset(amp->event_mask, 0, sizeof(amp->event_mask));
	amp->event_mask[1] |= 0x20;	/* Command Complete */
	amp->event_mask[1] |= 0x40;	/* Command Status */
	amp->event_mask[1] |= 0x80;	/* Hardware Error */
	amp->event_mask[2] |= 0x01;	/* Flush Occurred */
	amp->event_mask[2] |= 0x04;	/* Number of Completed Packets */
	amp->event_mask[3] |= 0x02;	/* Data Buffer Overflow */
	amp->event_mask[3] |= 0x20;	/* QoS Violation */
	amp->event_mask[7] |= 0x01;	/* Enhanced Flush Complete */

	amp->event_mask[8] |= 0x01;	/* Physical Link Complete */
	amp->event_mask[8] |= 0x02;	/* Channel Selected */
	amp->event_mask[8] |= 0x04;	/* Disconnection Physical Link Complete */
	amp->event_mask[8] |= 0x08;	/* Physical Link Loss Early Warning */
	amp->event_mask[8] |= 0x10;	/* Physical Link Recovery */
	amp->event_mask[8] |= 0x20;	/* Logical Link Complete */
	amp->event_mask[8] |= 0x40;	/* Disconection Logical Link Complete */
	amp->event_mask[8] |= 0x80;	/* Flow Specification Modify Complete */
	amp->event_mask[9] |= 0x01;	/* Number of Completed Data Blocks */
	amp->event_mask[9] |= 0x02;	/* AMP Start Test */
	amp->event_mask[9] |= 0x04;	/* AMP Test End */
	amp->event_mask[9] |= 0x08;	/* AMP Receiver Report */
	amp->event_mask[9] |= 0x10;	/* Short Range Mode Change Complete */
	amp->event_mask[9] |= 0x20;	/* AMP Status Change */

	amp->manufacturer = 0x003f;	/* Bluetooth SIG (63) */

	memset(amp->commands, 0, sizeof(amp->commands));
	amp->commands[5]  |= 0x40;	/* Set Event Mask */
	amp->commands[5]  |= 0x80;	/* Reset */
	//amp->commands[6]  |= 0x01;	/* Set Event Filter */
	//amp->commands[7]  |= 0x04;	/* Read Connection Accept Timeout */
	//amp->commands[7]  |= 0x08;	/* Write Connection Accept Timeout */
	//amp->commands[10] |= 0x80;	/* Host Number of Completed Packets */
	//amp->commands[11] |= 0x01;	/* Read Link Supervision Timeout */
	//amp->commands[11] |= 0x02;	/* Write Link Supervision Timeout */
	amp->commands[14] |= 0x08;	/* Read Local Version Information */
	amp->commands[14] |= 0x10;	/* Read Local Supported Commands */
	amp->commands[14] |= 0x20;	/* Read Local Supported Features */
	amp->commands[14] |= 0x80;	/* Read Buffer Size */
	//amp->commands[15] |= 0x04;	/* Read Failed Contact Counter */
	//amp->commands[15] |= 0x08;	/* Reset Failed Contact Counter */
	//amp->commands[15] |= 0x10;	/* Read Link Quality */
	//amp->commands[15] |= 0x20;	/* Read RSSI */
	//amp->commands[16] |= 0x04;	/* Enable Device Under Test Mode */
	//amp->commands[19] |= 0x40;	/* Enhanced Flush */

	amp->commands[21] |= 0x01;	/* Create Physical Link */
	amp->commands[21] |= 0x02;	/* Accept Physical Link */
	amp->commands[21] |= 0x04;	/* Disconnect Phyiscal Link */
	amp->commands[21] |= 0x08;	/* Create Logical Link */
	amp->commands[21] |= 0x10;	/* Accept Logical Link */
	amp->commands[21] |= 0x20;	/* Disconnect Logical Link */
	amp->commands[21] |= 0x40;	/* Logical Link Cancel */
	//amp->commands[21] |= 0x80;	/* Flow Specification Modify */
	//amp->commands[22] |= 0x01;	/* Read Logical Link Accept Timeout */
	//amp->commands[22] |= 0x02;	/* Write Logical Link Accept Timeout */
	amp->commands[22] |= 0x04;	/* Set Event Mask Page 2 */
	amp->commands[22] |= 0x08;	/* Read Location Data */
	amp->commands[22] |= 0x10;	/* Write Location Data */
	amp->commands[22] |= 0x20;	/* Read Local AMP Info */
	amp->commands[22] |= 0x40;	/* Read Local AMP ASSOC */
	amp->commands[22] |= 0x80;	/* Write Remote AMP ASSOC */
	amp->commands[23] |= 0x01;	/* Read Flow Control Mode */
	amp->commands[23] |= 0x02;	/* Write Flow Control Mode */
	amp->commands[23] |= 0x04;	/* Read Data Block Size */
	//amp->commands[23] |= 0x20;	/* Enable AMP Receiver Reports */
	//amp->commands[23] |= 0x40;	/* AMP Test End */
	//amp->commands[23] |= 0x80;	/* AMP Test */
	//amp->commands[24] |= 0x04;	/* Read Best Effort Flush Timeout */
	//amp->commands[24] |= 0x08;	/* Write Best Effort Flush Timeout */
	//amp->commands[24] |= 0x10;	/* Short Range Mode */

	memset(amp->features, 0, sizeof(amp->features));

	amp->amp_status = 0x01;		/* Used for Bluetooth only */
	amp->amp_type = 0x42;		/* Fake virtual AMP type */

	memset(amp->local_assoc, 0, sizeof(amp->local_assoc));
	amp->local_assoc_len = 0;

	memset(amp->remote_assoc, 0, sizeof(amp->remote_assoc));
	amp->remote_assoc_len = 0;

	amp->phy_mode = PHY_MODE_IDLE;
	amp->phy_handle = 0x00;		/* Invalid physical link handle */
	amp->logic_handle = 0x0000;
}

static void send_packet(struct bt_amp *amp, const void *data, uint16_t len)
{
	if (write(amp->vhci_fd, data, len) < 0)
		fprintf(stderr, "Write to /dev/vhci failed\n");
}

{'fraction_non_alphanumeric': 0.1625842008573178, 'fraction_numerical': 0.06146662584200857, 'mean_word_length': 3.798016893132574, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 195, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5953659', 'n_tokens_mistral': 5369, 'n_tokens_neox': 4828, 'n_words': 1290}