2018-11-12 22:11:36 -08:00
|
|
|
//
|
|
|
|
|
// main.m
|
|
|
|
|
// kordophone
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 11/12/18.
|
|
|
|
|
// Copyright © 2018 James Magahern. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
|
|
#import "MBIMBridge.h"
|
|
|
|
|
|
2019-01-22 23:31:36 -08:00
|
|
|
void printUsage()
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Usage: kordophoned [-h] [-s | -c (certificate.p12)]\n");
|
|
|
|
|
fprintf(stderr, "\t-h \t Show this help message\n");
|
|
|
|
|
fprintf(stderr, "\t-s \t Use SSL (requires -c option)\n");
|
|
|
|
|
fprintf(stderr, "\t-c \t SSL certificate path encoded as pkcs12\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *const argv[]) {
|
2018-11-12 22:11:36 -08:00
|
|
|
@autoreleasepool {
|
2019-01-22 23:31:36 -08:00
|
|
|
BOOL usesSSL = NO;
|
|
|
|
|
BOOL showHelp = NO;
|
|
|
|
|
const char *certPath = NULL;
|
2018-11-13 22:39:03 -08:00
|
|
|
|
2019-01-22 23:31:36 -08:00
|
|
|
int c = -1;
|
|
|
|
|
while ( (c = getopt(argc, argv, "hsc:")) != -1 ) {
|
|
|
|
|
switch (c) {
|
|
|
|
|
case 's':
|
|
|
|
|
usesSSL = YES;
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
certPath = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
showHelp = YES;
|
|
|
|
|
break;
|
|
|
|
|
case '?':
|
|
|
|
|
if (optopt == 'c') {
|
|
|
|
|
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
|
|
|
|
} else if (isprint(optopt)) {
|
|
|
|
|
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showHelp) {
|
|
|
|
|
printUsage();
|
2018-11-13 22:39:03 -08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 23:31:36 -08:00
|
|
|
if (usesSSL && certPath == NULL) {
|
|
|
|
|
fprintf(stderr, "Error: wants SSL (-s) but no ssl certificate path (-c) provided\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MBIMBridge *bridge = [MBIMBridge sharedInstance];
|
|
|
|
|
|
|
|
|
|
if (usesSSL && certPath != NULL) {
|
|
|
|
|
bridge.usesSSL = YES;
|
|
|
|
|
bridge.sslCertPath = [NSString stringWithCString:certPath encoding:NSASCIIStringEncoding];
|
|
|
|
|
}
|
2018-11-13 22:39:03 -08:00
|
|
|
|
2018-11-12 22:11:36 -08:00
|
|
|
[bridge connect];
|
|
|
|
|
|
|
|
|
|
BOOL running = YES;
|
|
|
|
|
while (running) {
|
|
|
|
|
[[NSRunLoop currentRunLoop] run];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-22 23:31:36 -08:00
|
|
|
|
2018-11-12 22:11:36 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|