1956f54b391677d78379729dd14518edddf3c7660Etan Cohen/*
2956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Copyright 2016, The Android Open Source Project
3956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
4956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Licensed under the Apache License, Version 2.0 (the "License");
5956f54b391677d78379729dd14518edddf3c7660Etan Cohen * you may not use this file except in compliance with the License.
6956f54b391677d78379729dd14518edddf3c7660Etan Cohen * You may obtain a copy of the License at
7956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
8956f54b391677d78379729dd14518edddf3c7660Etan Cohen *     http://www.apache.org/licenses/LICENSE-2.0
9956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
10956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Unless required by applicable law or agreed to in writing, software
11956f54b391677d78379729dd14518edddf3c7660Etan Cohen * distributed under the License is distributed on an "AS IS" BASIS,
12956f54b391677d78379729dd14518edddf3c7660Etan Cohen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13956f54b391677d78379729dd14518edddf3c7660Etan Cohen * See the License for the specific language governing permissions and
14956f54b391677d78379729dd14518edddf3c7660Etan Cohen * limitations under the License.
15956f54b391677d78379729dd14518edddf3c7660Etan Cohen */
16956f54b391677d78379729dd14518edddf3c7660Etan Cohen
17956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <stdint.h>
18956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include "JniConstants.h"
19956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <ScopedUtfChars.h>
20956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <ScopedBytes.h>
21956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <utils/misc.h>
22956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <android_runtime/AndroidRuntime.h>
23956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <utils/Log.h>
24956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <utils/String16.h>
25956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <ctype.h>
26956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <sys/socket.h>
27956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <linux/if.h>
28956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include "wifi.h"
29956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include "wifi_hal.h"
30956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include "jni_helper.h"
31956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include "wifi_hal_mock.h"
32956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <sstream>
33956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <rapidjson/document.h>
34956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <rapidjson/stringbuffer.h>
35956f54b391677d78379729dd14518edddf3c7660Etan Cohen#include <rapidjson/writer.h>
36956f54b391677d78379729dd14518edddf3c7660Etan Cohen
37956f54b391677d78379729dd14518edddf3c7660Etan Cohennamespace android {
38956f54b391677d78379729dd14518edddf3c7660Etan Cohen
39956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern jobject mock_mObj; /* saved NanHalMock object */
40956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern JavaVM* mock_mVM; /* saved JVM pointer */
41956f54b391677d78379729dd14518edddf3c7660Etan Cohen
42956f54b391677d78379729dd14518edddf3c7660Etan Cohen/* Variable and function declared and defined in:
43956f54b391677d78379729dd14518edddf3c7660Etan Cohen *  com_android_servier_wifi_nan_WifiNanNative.cpp
44956f54b391677d78379729dd14518edddf3c7660Etan Cohen */
45956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern wifi_hal_fn hal_fn;
46956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" jint Java_com_android_server_wifi_nan_WifiNanNative_registerNanNatives(
47956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz);
48956f54b391677d78379729dd14518edddf3c7660Etan Cohen
49956f54b391677d78379729dd14518edddf3c7660Etan Cohenstatic NanCallbackHandler mCallbackHandlers;
50956f54b391677d78379729dd14518edddf3c7660Etan Cohen
51956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_enable_request_mock(transaction_id id,
52956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                        wifi_interface_handle iface,
53956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                        NanEnableRequest* msg) {
54956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
55956f54b391677d78379729dd14518edddf3c7660Etan Cohen
56956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_enable_request_mock");
57956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
58956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("master_pref", msg->master_pref);
59956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("cluster_low", msg->cluster_low);
60956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("cluster_high", msg->cluster_high);
61956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_support_5g", msg->config_support_5g);
62956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("support_5g_val", msg->support_5g_val);
63956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_sid_beacon", msg->config_sid_beacon);
64956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("sid_beacon_val", msg->sid_beacon_val);
65956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_rssi_close", msg->config_2dot4g_rssi_close);
66956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_close_2dot4g_val", msg->rssi_close_2dot4g_val);
67956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_rssi_middle", msg->config_2dot4g_rssi_middle);
68956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_middle_2dot4g_val", msg->rssi_middle_2dot4g_val);
69956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_rssi_proximity",
70956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->config_2dot4g_rssi_proximity);
71956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_proximity_2dot4g_val", msg->rssi_proximity_2dot4g_val);
72956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_hop_count_limit", msg->config_hop_count_limit);
73956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("hop_count_limit_val", msg->hop_count_limit_val);
74956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_support", msg->config_2dot4g_support);
75956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("support_2dot4g_val", msg->support_2dot4g_val);
76956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_beacons", msg->config_2dot4g_beacons);
77956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("beacon_2dot4g_val", msg->beacon_2dot4g_val);
78956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_2dot4g_sdf", msg->config_2dot4g_sdf);
79956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("sdf_2dot4g_val", msg->sdf_2dot4g_val);
80956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_5g_beacons", msg->config_5g_beacons);
81956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("beacon_5g_val", msg->beacon_5g_val);
82956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_5g_sdf", msg->config_5g_sdf);
83956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("sdf_5g_val", msg->sdf_5g_val);
84956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_5g_rssi_close", msg->config_5g_rssi_close);
85956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_close_5g_val", msg->rssi_close_5g_val);
86956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_5g_rssi_middle", msg->config_5g_rssi_middle);
87956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_middle_5g_val", msg->rssi_middle_5g_val);
88956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_5g_rssi_close_proximity",
89956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->config_5g_rssi_close_proximity);
90956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_close_proximity_5g_val",
91956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->rssi_close_proximity_5g_val);
92956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_rssi_window_size", msg->config_rssi_window_size);
93956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_window_size_val", msg->rssi_window_size_val);
94956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_oui", msg->config_oui);
95956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("oui_val", msg->oui_val);
96956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_intf_addr", msg->config_intf_addr);
97956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("intf_addr_val", msg->intf_addr_val, 6);
98956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_cluster_attribute_val",
99956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->config_cluster_attribute_val);
100956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_scan_params", msg->config_scan_params);
101956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.dwell_time.0",
102956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.dwell_time[NAN_CHANNEL_24G_BAND]);
103956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.dwell_time.1",
104956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.dwell_time[NAN_CHANNEL_5G_BAND_LOW]);
105956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.dwell_time.2",
106956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.dwell_time[NAN_CHANNEL_5G_BAND_HIGH]);
107956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.scan_period.0",
108956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.scan_period[NAN_CHANNEL_24G_BAND]);
109956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.scan_period.0",
110956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.scan_period[NAN_CHANNEL_5G_BAND_LOW]);
111956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("scan_params_val.scan_period.0",
112956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->scan_params_val.scan_period[NAN_CHANNEL_5G_BAND_HIGH]);
113956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_random_factor_force", msg->config_random_factor_force);
114956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("random_factor_force_val", msg->random_factor_force_val);
115956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("config_hop_count_force", msg->config_hop_count_force);
116956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("hop_count_force_val", msg->hop_count_force_val);
117956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
118956f54b391677d78379729dd14518edddf3c7660Etan Cohen
119956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
120956f54b391677d78379729dd14518edddf3c7660Etan Cohen
121956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "enableHalMockNative", "(SLjava/lang/String;)V",
122956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    (short) id, json_write_string.get());
123956f54b391677d78379729dd14518edddf3c7660Etan Cohen
124956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
125956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
126956f54b391677d78379729dd14518edddf3c7660Etan Cohen
127956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_disable_request_mock(transaction_id id,
128956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                         wifi_interface_handle iface) {
129956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
130956f54b391677d78379729dd14518edddf3c7660Etan Cohen
131956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_disable_request_mock");
132956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "disableHalMockNative", "(S)V", (short) id);
133956f54b391677d78379729dd14518edddf3c7660Etan Cohen
134956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
135956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
136956f54b391677d78379729dd14518edddf3c7660Etan Cohen
137956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_publish_request_mock(transaction_id id,
138956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                         wifi_interface_handle iface,
139956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                         NanPublishRequest* msg) {
140956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
141956f54b391677d78379729dd14518edddf3c7660Etan Cohen
142956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_publish_request_mock");
143956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
144956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_id", msg->publish_id);
145956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("ttl", msg->ttl);
146956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_type", msg->publish_type);
147956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("tx_type", msg->tx_type);
148956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_count", msg->publish_count);
149956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("service_name_len", msg->service_name_len);
150956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("service_name", msg->service_name,
151956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->service_name_len);
152956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_match_indicator", msg->publish_match_indicator);
153956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("service_specific_info_len", msg->service_specific_info_len);
154956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("service_specific_info", msg->service_specific_info,
155956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->service_specific_info_len);
156956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rx_match_filter_len", msg->rx_match_filter_len);
157956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("rx_match_filter", msg->rx_match_filter,
158956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->rx_match_filter_len);
159956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("tx_match_filter_len", msg->tx_match_filter_len);
160956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("tx_match_filter", msg->tx_match_filter,
161956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->tx_match_filter_len);
162956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_threshold_flag", msg->rssi_threshold_flag);
163956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("connmap", msg->connmap);
164956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
165956f54b391677d78379729dd14518edddf3c7660Etan Cohen
166956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
167956f54b391677d78379729dd14518edddf3c7660Etan Cohen
168956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "publishHalMockNative", "(SLjava/lang/String;)V",
169956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    (short) id, json_write_string.get());
170956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
171956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
172956f54b391677d78379729dd14518edddf3c7660Etan Cohen
173956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_publish_cancel_request_mock(transaction_id id,
174956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                                wifi_interface_handle iface,
175956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                                NanPublishCancelRequest* msg) {
176956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
177956f54b391677d78379729dd14518edddf3c7660Etan Cohen
178956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_publish_cancel_request_mock");
179956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
180956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_id", msg->publish_id);
181956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
182956f54b391677d78379729dd14518edddf3c7660Etan Cohen
183956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
184956f54b391677d78379729dd14518edddf3c7660Etan Cohen
185956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "publishCancelHalMockNative",
186956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    "(SLjava/lang/String;)V", (short) id,
187956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    json_write_string.get());
188956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
189956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
190956f54b391677d78379729dd14518edddf3c7660Etan Cohen
191956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_subscribe_request_mock(transaction_id id,
192956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                           wifi_interface_handle iface,
193956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                           NanSubscribeRequest* msg) {
194956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
195956f54b391677d78379729dd14518edddf3c7660Etan Cohen
196956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_subscribe_request_mock");
197956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
198956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("subscribe_id", msg->subscribe_id);
199956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("ttl", msg->ttl);
200956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("period", msg->period);
201956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("subscribe_type", msg->subscribe_type);
202956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("serviceResponseFilter", msg->serviceResponseFilter);
203956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("serviceResponseInclude", msg->serviceResponseInclude);
204956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("useServiceResponseFilter", msg->useServiceResponseFilter);
205956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("ssiRequiredForMatchIndication",
206956f54b391677d78379729dd14518edddf3c7660Etan Cohen                msg->ssiRequiredForMatchIndication);
207956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("subscribe_match_indicator", msg->subscribe_match_indicator);
208956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("subscribe_count", msg->subscribe_count);
209956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("service_name_len", msg->service_name_len);
210956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("service_name", msg->service_name,
211956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->service_name_len);
212956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("service_specific_info_len", msg->service_name_len);
213956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("service_specific_info", msg->service_specific_info,
214956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->service_specific_info_len);
215956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rx_match_filter_len", msg->rx_match_filter_len);
216956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("rx_match_filter", msg->rx_match_filter,
217956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->rx_match_filter_len);
218956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("tx_match_filter_len", msg->tx_match_filter_len);
219956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("tx_match_filter", msg->tx_match_filter,
220956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->tx_match_filter_len);
221956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("rssi_threshold_flag", msg->rssi_threshold_flag);
222956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("connmap", msg->connmap);
223956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("num_intf_addr_present", msg->num_intf_addr_present);
224956f54b391677d78379729dd14518edddf3c7660Etan Cohen  // TODO: jsonW.put_byte_array("intf_addr", msg->intf_addr, NAN_MAX_SUBSCRIBE_MAX_ADDRESS * NAN_MAC_ADDR_LEN);
225956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
226956f54b391677d78379729dd14518edddf3c7660Etan Cohen
227956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
228956f54b391677d78379729dd14518edddf3c7660Etan Cohen
229956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "subscribeHalMockNative",
230956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    "(SLjava/lang/String;)V", (short) id,
231956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    json_write_string.get());
232956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
233956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
234956f54b391677d78379729dd14518edddf3c7660Etan Cohen
235956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_subscribe_cancel_request_mock(
236956f54b391677d78379729dd14518edddf3c7660Etan Cohen    transaction_id id, wifi_interface_handle iface,
237956f54b391677d78379729dd14518edddf3c7660Etan Cohen    NanSubscribeCancelRequest* msg) {
238956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
239956f54b391677d78379729dd14518edddf3c7660Etan Cohen
240956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_subscribe_cancel_request_mock");
241956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
242956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("subscribe_id", msg->subscribe_id);
243956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
244956f54b391677d78379729dd14518edddf3c7660Etan Cohen
245956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
246956f54b391677d78379729dd14518edddf3c7660Etan Cohen
247956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "subscribeCancelHalMockNative",
248956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    "(SLjava/lang/String;)V", (short) id,
249956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    json_write_string.get());
250956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
251956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
252956f54b391677d78379729dd14518edddf3c7660Etan Cohen
253956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_transmit_followup_request_mock(
254956f54b391677d78379729dd14518edddf3c7660Etan Cohen    transaction_id id, wifi_interface_handle iface,
255956f54b391677d78379729dd14518edddf3c7660Etan Cohen    NanTransmitFollowupRequest* msg) {
256956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIHelper helper(mock_mVM);
257956f54b391677d78379729dd14518edddf3c7660Etan Cohen
258956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_transmit_followup_request_mock");
259956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonWriter jsonW;
260956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("publish_subscribe_id", msg->publish_subscribe_id);
261956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("requestor_instance_id", msg->requestor_instance_id);
262956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("addr", msg->addr, 6);
263956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("priority", msg->priority);
264956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("dw_or_faw", msg->dw_or_faw);
265956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_int("service_specific_info_len", msg->service_specific_info_len);
266956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonW.put_byte_array("service_specific_info", msg->service_specific_info,
267956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg->service_specific_info_len);
268956f54b391677d78379729dd14518edddf3c7660Etan Cohen
269956f54b391677d78379729dd14518edddf3c7660Etan Cohen  std::string str = jsonW.to_string();
270956f54b391677d78379729dd14518edddf3c7660Etan Cohen
271956f54b391677d78379729dd14518edddf3c7660Etan Cohen  JNIObject < jstring > json_write_string = helper.newStringUTF(str.c_str());
272956f54b391677d78379729dd14518edddf3c7660Etan Cohen
273956f54b391677d78379729dd14518edddf3c7660Etan Cohen  helper.callMethod(mock_mObj, "transmitFollowupHalMockNative",
274956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    "(SLjava/lang/String;)V", (short) id,
275956f54b391677d78379729dd14518edddf3c7660Etan Cohen                    json_write_string.get());
276956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
277956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
278956f54b391677d78379729dd14518edddf3c7660Etan Cohen
279956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_stats_request_mock(transaction_id id,
280956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                       wifi_interface_handle iface,
281956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                       NanStatsRequest* msg) {
282956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_stats_request_mock");
283956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_ERROR_UNINITIALIZED;
284956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
285956f54b391677d78379729dd14518edddf3c7660Etan Cohen
286956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_config_request_mock(transaction_id id,
287956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                        wifi_interface_handle iface,
288956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                        NanConfigRequest* msg) {
289956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_config_request_mock");
290956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_ERROR_UNINITIALIZED;
291956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
292956f54b391677d78379729dd14518edddf3c7660Etan Cohen
293956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_tca_request_mock(transaction_id id,
294956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                     wifi_interface_handle iface,
295956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                     NanTCARequest* msg) {
296956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_tca_request_mock");
297956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_ERROR_UNINITIALIZED;
298956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
299956f54b391677d78379729dd14518edddf3c7660Etan Cohen
300956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_beacon_sdf_payload_request_mock(
301956f54b391677d78379729dd14518edddf3c7660Etan Cohen    transaction_id id, wifi_interface_handle iface,
302956f54b391677d78379729dd14518edddf3c7660Etan Cohen    NanBeaconSdfPayloadRequest* msg) {
303956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_beacon_sdf_payload_request_mock");
304956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_ERROR_UNINITIALIZED;
305956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
306956f54b391677d78379729dd14518edddf3c7660Etan Cohen
307956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_register_handler_mock(wifi_interface_handle iface,
308956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                          NanCallbackHandler handlers) {
309956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_register_handler_mock");
310956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers = handlers;
311956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_SUCCESS;
312956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
313956f54b391677d78379729dd14518edddf3c7660Etan Cohen
314956f54b391677d78379729dd14518edddf3c7660Etan Cohenwifi_error wifi_nan_get_version_mock(wifi_handle handle, NanVersion* version) {
315956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("wifi_nan_get_version_mock");
316956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return WIFI_ERROR_UNINITIALIZED;
317956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
318956f54b391677d78379729dd14518edddf3c7660Etan Cohen
319e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohenwifi_error wifi_nan_get_capabilities_mock(transaction_id id,
320e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen                                          wifi_interface_handle iface) {
321e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen  JNIHelper helper(mock_mVM);
322e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen
323e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen  ALOGD("wifi_nan_get_capabilities_mock");
324e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen
325e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen  helper.callMethod(mock_mObj, "getCapabilitiesHalMockNative", "(S)V",
326e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen                    (short) id);
327e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen  return WIFI_SUCCESS;
328e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen}
329e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen
330956f54b391677d78379729dd14518edddf3c7660Etan Cohen// Callbacks
331956f54b391677d78379729dd14518edddf3c7660Etan Cohen
332956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callNotifyResponse(
333956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jshort transaction_id,
334956f54b391677d78379729dd14518edddf3c7660Etan Cohen    jstring json_args_jstring) {
335956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
336956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
337956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
338956f54b391677d78379729dd14518edddf3c7660Etan Cohen
339956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("Java_com_android_server_wifi_nan_WifiNanHalMock_callNotifyResponse: '%s'",
340956f54b391677d78379729dd14518edddf3c7660Etan Cohen        chars.c_str());
341956f54b391677d78379729dd14518edddf3c7660Etan Cohen
342956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanResponseMsg msg;
343956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.status = (NanStatusType) jsonR.get_int("status", &error);
344956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.value = jsonR.get_int("value", &error);
345956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.response_type = (NanResponseType) jsonR.get_int("response_type", &error);
346956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (msg.response_type == NAN_RESPONSE_PUBLISH) {
347956f54b391677d78379729dd14518edddf3c7660Etan Cohen    msg.body.publish_response.publish_id = jsonR.get_int(
348956f54b391677d78379729dd14518edddf3c7660Etan Cohen        "body.publish_response.publish_id", &error);
349956f54b391677d78379729dd14518edddf3c7660Etan Cohen  } else if (msg.response_type == NAN_RESPONSE_SUBSCRIBE) {
350956f54b391677d78379729dd14518edddf3c7660Etan Cohen    msg.body.subscribe_response.subscribe_id = jsonR.get_int(
351956f54b391677d78379729dd14518edddf3c7660Etan Cohen        "body.subscribe_response.subscribe_id", &error);
352e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen  } else if (msg.response_type == NAN_GET_CAPABILITIES) {
353e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_concurrent_nan_clusters = jsonR.get_int(
354e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_concurrent_nan_clusters", &error);
355e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_publishes = jsonR.get_int(
356e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_publishes", &error);
357e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_subscribes = jsonR.get_int(
358e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_subscribes", &error);
359e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_service_name_len = jsonR.get_int(
360e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_service_name_len", &error);
361e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_match_filter_len = jsonR.get_int(
362e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_match_filter_len", &error);
363e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_total_match_filter_len = jsonR.get_int(
364e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_total_match_filter_len", &error);
365e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_service_specific_info_len = jsonR.get_int(
366e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_service_specific_info_len", &error);
367e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_vsa_data_len = jsonR.get_int(
368e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_vsa_data_len", &error);
369e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_mesh_data_len = jsonR.get_int(
370e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_mesh_data_len", &error);
371e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_ndi_interfaces = jsonR.get_int(
372e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_ndi_interfaces", &error);
373e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_ndp_sessions = jsonR.get_int(
374e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_ndp_sessions", &error);
375e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    msg.body.nan_capabilities.max_app_info_len = jsonR.get_int(
376e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        "body.nan_capabilities.max_app_info_len", &error);
377956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
378956f54b391677d78379729dd14518edddf3c7660Etan Cohen
379956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
380956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callNotifyResponse: "
381956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
382956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
383956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
384956f54b391677d78379729dd14518edddf3c7660Etan Cohen
385956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.NotifyResponse(transaction_id, &msg);
386956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
387956f54b391677d78379729dd14518edddf3c7660Etan Cohen
388956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callPublishTerminated(
389956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
390956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
391956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
392956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
393956f54b391677d78379729dd14518edddf3c7660Etan Cohen
394956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD(
395956f54b391677d78379729dd14518edddf3c7660Etan Cohen      "Java_com_android_server_wifi_nan_WifiNanHalMock_callPublishTerminated: '%s'",
396956f54b391677d78379729dd14518edddf3c7660Etan Cohen      chars.c_str());
397956f54b391677d78379729dd14518edddf3c7660Etan Cohen
398956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanPublishTerminatedInd msg;
399956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.publish_id = jsonR.get_int("publish_id", &error);
400956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.reason = (NanStatusType) jsonR.get_int("reason", &error);
401956f54b391677d78379729dd14518edddf3c7660Etan Cohen
402956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
403956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callPublishTerminated: "
404956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
405956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
406956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
407956f54b391677d78379729dd14518edddf3c7660Etan Cohen
408956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventPublishTerminated(&msg);
409956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
410956f54b391677d78379729dd14518edddf3c7660Etan Cohen
411956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callSubscribeTerminated(
412956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
413956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
414956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
415956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
416956f54b391677d78379729dd14518edddf3c7660Etan Cohen
417956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD(
418956f54b391677d78379729dd14518edddf3c7660Etan Cohen      "Java_com_android_server_wifi_nan_WifiNanHalMock_callSubscribeTerminated: '%s'",
419956f54b391677d78379729dd14518edddf3c7660Etan Cohen      chars.c_str());
420956f54b391677d78379729dd14518edddf3c7660Etan Cohen
421956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanSubscribeTerminatedInd msg;
422956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.subscribe_id = jsonR.get_int("subscribe_id", &error);
423956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.reason = (NanStatusType) jsonR.get_int("reason", &error);
424956f54b391677d78379729dd14518edddf3c7660Etan Cohen
425956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
426956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callSubscribeTerminated:"
427956f54b391677d78379729dd14518edddf3c7660Etan Cohen          " error parsing args");
428956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
429956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
430956f54b391677d78379729dd14518edddf3c7660Etan Cohen
431956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventSubscribeTerminated(&msg);
432956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
433956f54b391677d78379729dd14518edddf3c7660Etan Cohen
434956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callFollowup(
435956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
436956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
437956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
438956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
439956f54b391677d78379729dd14518edddf3c7660Etan Cohen
440956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("Java_com_android_server_wifi_nan_WifiNanHalMock_callFollowup: '%s'",
441956f54b391677d78379729dd14518edddf3c7660Etan Cohen        chars.c_str());
442956f54b391677d78379729dd14518edddf3c7660Etan Cohen
443956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanFollowupInd msg;
444956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.publish_subscribe_id = jsonR.get_int("publish_subscribe_id", &error);
445956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.requestor_instance_id = jsonR.get_int("requestor_instance_id", &error);
446956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonR.get_byte_array("addr", &error, msg.addr, NAN_MAC_ADDR_LEN);
447956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.dw_or_faw = jsonR.get_int("dw_or_faw", &error);
448956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.service_specific_info_len = jsonR.get_int("service_specific_info_len",
449956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                                &error);
450956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonR.get_byte_array("service_specific_info", &error,
451956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg.service_specific_info,
452956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       NAN_MAX_SERVICE_SPECIFIC_INFO_LEN);
453956f54b391677d78379729dd14518edddf3c7660Etan Cohen
454956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
455956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callFollowup: "
456956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
457956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
458956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
459956f54b391677d78379729dd14518edddf3c7660Etan Cohen
460956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventFollowup(&msg);
461956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
462956f54b391677d78379729dd14518edddf3c7660Etan Cohen
463956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callMatch(
464956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
465956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
466956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
467956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
468956f54b391677d78379729dd14518edddf3c7660Etan Cohen
469956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("Java_com_android_server_wifi_nan_WifiNanHalMock_callMatch: '%s'",
470956f54b391677d78379729dd14518edddf3c7660Etan Cohen        chars.c_str());
471956f54b391677d78379729dd14518edddf3c7660Etan Cohen
472956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanMatchInd msg;
473956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.publish_subscribe_id = jsonR.get_int("publish_subscribe_id", &error);
474956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.requestor_instance_id = jsonR.get_int("requestor_instance_id", &error);
475956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonR.get_byte_array("addr", &error, msg.addr, NAN_MAC_ADDR_LEN);
476956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.service_specific_info_len = jsonR.get_int("service_specific_info_len",
477956f54b391677d78379729dd14518edddf3c7660Etan Cohen                                                &error);
478956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonR.get_byte_array("service_specific_info", &error,
479956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       msg.service_specific_info,
480956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       NAN_MAX_SERVICE_SPECIFIC_INFO_LEN);
481956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.sdf_match_filter_len = jsonR.get_int("sdf_match_filter_len", &error);
482956f54b391677d78379729dd14518edddf3c7660Etan Cohen  jsonR.get_byte_array("sdf_match_filter", &error, msg.sdf_match_filter,
483956f54b391677d78379729dd14518edddf3c7660Etan Cohen                       NAN_MAX_MATCH_FILTER_LEN);
484956f54b391677d78379729dd14518edddf3c7660Etan Cohen  /* a few more fields here - but not used (yet/never?) */
485956f54b391677d78379729dd14518edddf3c7660Etan Cohen
486956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
487956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callMatch: "
488956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
489956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
490956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
491956f54b391677d78379729dd14518edddf3c7660Etan Cohen
492956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventMatch(&msg);
493956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
494956f54b391677d78379729dd14518edddf3c7660Etan Cohen
495956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callDiscEngEvent(
496956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
497956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
498956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
499956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
500956f54b391677d78379729dd14518edddf3c7660Etan Cohen
501956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("Java_com_android_server_wifi_nan_WifiNanHalMock_callDiscEngEvent: '%s'",
502956f54b391677d78379729dd14518edddf3c7660Etan Cohen        chars.c_str());
503956f54b391677d78379729dd14518edddf3c7660Etan Cohen
504956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanDiscEngEventInd msg;
505956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.event_type = (NanDiscEngEventType) jsonR.get_int("event_type", &error);
506956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (msg.event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
507956f54b391677d78379729dd14518edddf3c7660Etan Cohen    jsonR.get_byte_array("data", &error, msg.data.mac_addr.addr,
508956f54b391677d78379729dd14518edddf3c7660Etan Cohen                         NAN_MAC_ADDR_LEN);
509956f54b391677d78379729dd14518edddf3c7660Etan Cohen  } else {
510956f54b391677d78379729dd14518edddf3c7660Etan Cohen    jsonR.get_byte_array("data", &error, msg.data.cluster.addr,
511956f54b391677d78379729dd14518edddf3c7660Etan Cohen                         NAN_MAC_ADDR_LEN);
512956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
513956f54b391677d78379729dd14518edddf3c7660Etan Cohen
514956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
515956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callDiscEngEvent: "
516956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
517956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
518956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
519956f54b391677d78379729dd14518edddf3c7660Etan Cohen
520956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventDiscEngEvent(&msg);
521956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
522956f54b391677d78379729dd14518edddf3c7660Etan Cohen
523956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" void Java_com_android_server_wifi_nan_WifiNanHalMock_callDisabled(
524956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz, jstring json_args_jstring) {
525956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ScopedUtfChars chars(env, json_args_jstring);
526956f54b391677d78379729dd14518edddf3c7660Etan Cohen  HalMockJsonReader jsonR(chars.c_str());
527956f54b391677d78379729dd14518edddf3c7660Etan Cohen  bool error = false;
528956f54b391677d78379729dd14518edddf3c7660Etan Cohen
529956f54b391677d78379729dd14518edddf3c7660Etan Cohen  ALOGD("Java_com_android_server_wifi_nan_WifiNanHalMock_callDisabled: '%s'",
530956f54b391677d78379729dd14518edddf3c7660Etan Cohen        chars.c_str());
531956f54b391677d78379729dd14518edddf3c7660Etan Cohen
532956f54b391677d78379729dd14518edddf3c7660Etan Cohen  NanDisabledInd msg;
533956f54b391677d78379729dd14518edddf3c7660Etan Cohen  msg.reason = (NanStatusType) jsonR.get_int("reason", &error);
534956f54b391677d78379729dd14518edddf3c7660Etan Cohen
535956f54b391677d78379729dd14518edddf3c7660Etan Cohen  if (error) {
536956f54b391677d78379729dd14518edddf3c7660Etan Cohen    ALOGE("Java_com_android_server_wifi_nan_WifiNanHalMock_callDisabled: "
537956f54b391677d78379729dd14518edddf3c7660Etan Cohen          "error parsing args");
538956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return;
539956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
540956f54b391677d78379729dd14518edddf3c7660Etan Cohen
541956f54b391677d78379729dd14518edddf3c7660Etan Cohen  mCallbackHandlers.EventDisabled(&msg);
542956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
543956f54b391677d78379729dd14518edddf3c7660Etan Cohen
544956f54b391677d78379729dd14518edddf3c7660Etan Cohen// TODO: Not currently used: add as needed
545956f54b391677d78379729dd14518edddf3c7660Etan Cohen//void (*EventUnMatch) (NanUnmatchInd* event);
546956f54b391677d78379729dd14518edddf3c7660Etan Cohen//void (*EventTca) (NanTCAInd* event);
547956f54b391677d78379729dd14518edddf3c7660Etan Cohen//void (*EventBeaconSdfPayload) (NanBeaconSdfPayloadInd* event);
548956f54b391677d78379729dd14518edddf3c7660Etan Cohen
54980fcd6da60c59a395c4154feae75d1015bc9691eMitchell Willsint init_wifi_nan_hal_func_table_mock(wifi_hal_fn *fn) {
55080fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  if (fn == NULL) {
551956f54b391677d78379729dd14518edddf3c7660Etan Cohen    return -1;
552956f54b391677d78379729dd14518edddf3c7660Etan Cohen  }
553956f54b391677d78379729dd14518edddf3c7660Etan Cohen
55480fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_enable_request = wifi_nan_enable_request_mock;
55580fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_disable_request = wifi_nan_disable_request_mock;
55680fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_publish_request = wifi_nan_publish_request_mock;
55780fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_publish_cancel_request =
558956f54b391677d78379729dd14518edddf3c7660Etan Cohen      wifi_nan_publish_cancel_request_mock;
55980fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_subscribe_request = wifi_nan_subscribe_request_mock;
56080fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_subscribe_cancel_request =
561956f54b391677d78379729dd14518edddf3c7660Etan Cohen      wifi_nan_subscribe_cancel_request_mock;
56280fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_transmit_followup_request =
563956f54b391677d78379729dd14518edddf3c7660Etan Cohen      wifi_nan_transmit_followup_request_mock;
56480fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_stats_request = wifi_nan_stats_request_mock;
56580fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_config_request = wifi_nan_config_request_mock;
56680fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_tca_request = wifi_nan_tca_request_mock;
56780fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_beacon_sdf_payload_request =
568956f54b391677d78379729dd14518edddf3c7660Etan Cohen      wifi_nan_beacon_sdf_payload_request_mock;
56980fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_register_handler = wifi_nan_register_handler_mock;
57080fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_get_version = wifi_nan_get_version_mock;
57180fcd6da60c59a395c4154feae75d1015bc9691eMitchell Wills  fn->wifi_nan_get_capabilities = wifi_nan_get_capabilities_mock;
572956f54b391677d78379729dd14518edddf3c7660Etan Cohen
573956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return 0;
574956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
575956f54b391677d78379729dd14518edddf3c7660Etan Cohen
576956f54b391677d78379729dd14518edddf3c7660Etan Cohenextern "C" jint Java_com_android_server_wifi_nan_WifiNanHalMock_initNanHalMock(
577956f54b391677d78379729dd14518edddf3c7660Etan Cohen    JNIEnv* env, jclass clazz) {
578956f54b391677d78379729dd14518edddf3c7660Etan Cohen  Java_com_android_server_wifi_nan_WifiNanNative_registerNanNatives(env, clazz);
579956f54b391677d78379729dd14518edddf3c7660Etan Cohen  return init_wifi_nan_hal_func_table_mock(&hal_fn);
580956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
581956f54b391677d78379729dd14518edddf3c7660Etan Cohen
582956f54b391677d78379729dd14518edddf3c7660Etan Cohen}// namespace android
583