Skip to content

Commit

Permalink
Initial implementation and makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
David Herzka committed Sep 28, 2017
1 parent df33bb7 commit baf2099
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CFLAGS = -Wall -Weverything -lobjc -framework IOBluetooth

build: btname

install: build
install -m 755 btname /usr/local/bin/btname

uninstall:
${RM} /usr/local/bin/btname

clean:
${RM} btname
42 changes: 42 additions & 0 deletions btname.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#import <stdio.h>
#import <string.h>
#import <objc/objc.h>

@interface IOBluetoothHostController
+ (IOBluetoothHostController *)defaultController;
- (int)BluetoothHCIReadLocalName:(char[248])name;
- (int)BluetoothHCIWriteLocalName:(char[248])name;
@end

int main()
{
IOBluetoothHostController *controller = [IOBluetoothHostController defaultController];

char oldName[248];
[controller BluetoothHCIReadLocalName:oldName];
printf("Current bluetooth name is \"%s\". New name? ", oldName);

BOOL changed = false;
char newName[248];
if (fgets(newName, sizeof(newName), stdin) != NULL) {
// Get rid of newline at end
newName[strcspn(newName, "\n")] = '\0';

if (newName[0] != '\0') {
[controller BluetoothHCIWriteLocalName:newName];
changed = true;
}
} else {
printf("\n");
}

if (changed) {
// Read again for good measure
[controller BluetoothHCIReadLocalName:newName];
printf("Bluetooth name has been changed to \"%s\"\n", newName);
} else {
printf("Name not changed\n");
}

return 0;
}

0 comments on commit baf2099

Please sign in to comment.