JLChen
2019-12-05 ec3f0ff822398d752511d516d0f3873e24c3fd41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
#include <elian.h>
#include "elianjni.h"
 
//#define ENCKEY "McdwCnwCdss2_18p"
 
static void *context = NULL;
 
JNIEXPORT jint JNICALL Java_com_mediatek_elian_ElianNative_GetProtoVersion
  (JNIEnv *, jobject)
{
    int protoVersion = 0;
    int libVersion = 0;
 
    elianGetVersion(&protoVersion, &libVersion);
    return protoVersion;
}
 
JNIEXPORT jint JNICALL Java_com_mediatek_elian_ElianNative_GetLibVersion
  (JNIEnv *, jobject)
{
    int protoVersion = 0;
    int libVersion = 0;
 
    elianGetVersion(&protoVersion, &libVersion);
    return libVersion;
}
 
JNIEXPORT jint JNICALL Java_com_mediatek_elian_ElianNative_InitSmartConnection
  (JNIEnv *, jobject, jstring, jint sendV1, jint sendV4)
{
    unsigned char target[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    unsigned int flag = 0;
 
    if (context)
    {
        elianStop(context);
        elianDestroy(context);
        context = NULL;
    }
 
    if (sendV1)
    {
        flag |= ELIAN_SEND_V1;
    }
    if (sendV4)
    {
        flag |= ELIAN_SEND_V4;
    }
    context = elianNew(NULL, 0, target, flag);
    if (context == NULL)
    {
        return -1;
    }
    elianSetInterval(context, 20*1000);
    return 0;
}
 
/*
 * Class:     com_mediatek_elian_ElianNative
 * Method:    StartSmartConnection
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;B)I
 */
JNIEXPORT jint JNICALL Java_com_mediatek_elian_ElianNative_StartSmartConnection
  (JNIEnv *env, jobject, jstring SSID, jstring PASSWORD, jstring CUSTOM)
{
    const char *ssid = NULL;
    const char *password = NULL;
    const char *custom = NULL;
 
    if (context == NULL)
    {
        return -1;
    }
    ssid = env->GetStringUTFChars(SSID, 0);
    password = env->GetStringUTFChars(PASSWORD, 0);
    custom = env->GetStringUTFChars(CUSTOM, 0);
 
//    elianPut(context, TYPE_ID_AM, (char *)&authmode, 1);
    elianPut(context, TYPE_ID_SSID, (char *)ssid, strlen(ssid));
    elianPut(context, TYPE_ID_PWD, (char *)password, strlen(password));
    elianPut(context, TYPE_ID_CUST, (char *)custom, strlen(custom));
 
    env->ReleaseStringUTFChars(SSID, ssid);
    env->ReleaseStringUTFChars(PASSWORD, password);
    env->ReleaseStringUTFChars(CUSTOM, custom);
 
    elianStart(context);
 
    return 0;
}
 
/*
 * Class:     com_mediatek_elian_ElianNative
 * Method:    StopSmartConnection
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_mediatek_elian_ElianNative_StopSmartConnection
  (JNIEnv *, jobject)
{
    if (context)
    {
        elianStop(context);
        elianDestroy(context);
        context = NULL;
    }
    return 0;
}