mirror of
				https://github.com/Telecominfraproject/wlan-ap.git
				synced 2025-10-31 18:38:10 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			feeds_use_
			...
			v3.1.0-rc2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 21cb4de975 | 
							
								
								
									
										11
									
								
								.github/workflows/build-dev.yml
									
									
									
									
										vendored
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										11
									
								
								.github/workflows/build-dev.yml
									
									
									
									
										vendored
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -15,20 +15,21 @@ on: | |||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|   build: |   build: | ||||||
|     runs-on: ubuntu-22.04 |     runs-on: ubuntu-latest | ||||||
|     outputs: |     outputs: | ||||||
|       x64_vm_image_name: ${{ steps.package_and_upload_image.outputs.x64_vm_image_name }} |       x64_vm_image_name: ${{ steps.package_and_upload_image.outputs.x64_vm_image_name }} | ||||||
|     strategy: |     strategy: | ||||||
|       fail-fast: false |       fail-fast: false | ||||||
|       matrix: |       matrix: | ||||||
|         target: [ 'cig_wf189h', 'cig_wf189w', 'cig_wf660a', 'cig_wf672', 'cig_wf186h', 'cig_wf186w', 'cig_wf188n', 'cig_wf189', 'cig_wf196', 'cig_wf196', 'cybertan_eww631-a1', 'cybertan_eww631-b1', 'sonicfi_rap630w-312g', 'sonicfi_rap63xc-211g', 'sonicfi_rap630c-311g', 'sonicfi_rap630w-311g', 'sonicfi_rap630w-211g', 'sonicfi_rap650c', 'sonicfi_rap7110c-341x', 'sonicfi_rap750e-h', 'sonicfi_rap750e-s', 'sonicfi_rap750w-311a', 'edgecore_eap101', 'edgecore_eap102', 'edgecore_eap104', 'edgecore_eap105', 'edgecore_eap111', 'edgecore_eap112', 'edgecore_oap101', 'edgecore_oap101-6e', 'edgecore_oap101e', 'edgecore_oap101e-6e', 'edgecore_oap103', 'hfcl_ion4xe', 'hfcl_ion4xi', 'hfcl_ion4x', 'hfcl_ion4x_2', 'hfcl_ion4x_3', 'hfcl_ion4xi_w', 'hfcl_ion4x_w', 'indio_um-305ax', 'senao_iap4300m', 'senao_iap2300m', 'senao_jeap6500', 'udaya_a6-id2', 'udaya_a6-od2', 'yuncore_ax820', 'yuncore_ax840', 'yuncore_fap640', 'yuncore_fap650', 'yuncore_fap655', 'emplus_wap588m', 'zyxel_nwa130be', 'sercomm_ap72tip-v4' ] |         target: [ 'cig_wf186h', 'cig_wf186w', 'cig_wf188n', 'cig_wf196', 'cig_wf189', 'cybertan_eww631-a1', 'cybertan_eww631-b1', 'edgecore_eap101', 'edgecore_eap102', 'edgecore_eap104', 'edgecore_eap111', 'edgecore_ecw5211', 'edgecore_oap101', 'edgecore_oap101-6e', 'edgecore_oap101e', 'edgecore_oap101e-6e', 'hfcl_ion4', 'hfcl_ion4xe', 'hfcl_ion4xi', 'hfcl_ion4x', 'hfcl_ion4x_2', 'hfcl_ion4x_3', 'hfcl_ion4xi_w', 'hfcl_ion4x_w', 'indio_um-305ax', 'indio_um-325ac', 'indio_um-510ac-v3', 'indio_um-550ac', 'sercomm_ap72tip', 'udaya_a5-id2', 'udaya_a6-id2', 'wallys_dr40x9', 'wallys_dr6018', 'wallys_dr6018-v4', 'yuncore_ax820', 'yuncore_ax840', 'yuncore_fap640', 'yuncore_fap650', 'yuncore_fap655' ] | ||||||
|  |  | ||||||
|     steps: |     steps: | ||||||
|     - uses: actions/checkout@v3 |     - uses: actions/checkout@v3 | ||||||
|  |  | ||||||
|     # Clean unnecessary files to save disk space |     # Clean unnecessary files to save disk space | ||||||
|     - name: clean unncessary files to save space |     - name: clean unncessary files to save space | ||||||
|       run: | |       run: | | ||||||
|         docker rmi `docker images -q` || true |         docker rmi `docker images -q` | ||||||
|  |  | ||||||
|     - name: Build image for ${{ matrix.target }} |     - name: Build image for ${{ matrix.target }} | ||||||
|       id: build |       id: build | ||||||
| @@ -80,7 +81,7 @@ jobs: | |||||||
|         fi |         fi | ||||||
|  |  | ||||||
|   trigger-testing: |   trigger-testing: | ||||||
|     runs-on: ubuntu-22.04 |     runs-on: ubuntu-latest | ||||||
|     needs: build |     needs: build | ||||||
|     if: startsWith(github.ref, 'refs/tags/v') |     if: startsWith(github.ref, 'refs/tags/v') | ||||||
|     steps: |     steps: | ||||||
| @@ -93,7 +94,7 @@ jobs: | |||||||
|         client-payload: '{"ref": "${GITHUB_REF#refs/tags/}", "sha": "${{ github.sha }}"}' |         client-payload: '{"ref": "${GITHUB_REF#refs/tags/}", "sha": "${{ github.sha }}"}' | ||||||
|  |  | ||||||
|   create-x64_vm-ami: |   create-x64_vm-ami: | ||||||
|     runs-on: ubuntu-22.04 |     runs-on: ubuntu-latest | ||||||
|     needs: build |     needs: build | ||||||
|     if: startsWith(github.ref, 'refs/tags/v') |     if: startsWith(github.ref, 'refs/tags/v') | ||||||
|     steps: |     steps: | ||||||
|   | |||||||
| @@ -6,8 +6,7 @@ boot() { | |||||||
| 	. /lib/functions/system.sh | 	. /lib/functions/system.sh | ||||||
| 	case $(board_name) in | 	case $(board_name) in | ||||||
| 	edgecore,eap102|\ | 	edgecore,eap102|\ | ||||||
| 	edgecore,oap102|\ | 	edgecore,oap102) | ||||||
| 	edgecore,oap103) |  | ||||||
| 		echo 54 > /sys/class/gpio/export | 		echo 54 > /sys/class/gpio/export | ||||||
| 		echo out > /sys/class/gpio/gpio54/direction | 		echo out > /sys/class/gpio/gpio54/direction | ||||||
| 		echo 0 > /sys/class/gpio/gpio54/value | 		echo 0 > /sys/class/gpio/gpio54/value | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,738 +0,0 @@ | |||||||
| --- a/hostapd/Makefile |  | ||||||
| +++ b/hostapd/Makefile |  | ||||||
| @@ -166,6 +166,12 @@ OBJS += ../src/common/hw_features_common |  | ||||||
|   |  | ||||||
|  OBJS += ../src/eapol_auth/eapol_auth_sm.o |  | ||||||
|   |  | ||||||
| +ifdef CONFIG_UBUS |  | ||||||
| +CFLAGS += -DUBUS_SUPPORT |  | ||||||
| +OBJS += ../src/utils/uloop.o |  | ||||||
| +OBJS += ../src/ap/ubus.o |  | ||||||
| +LIBS += -lubox -lubus |  | ||||||
| +endif |  | ||||||
|   |  | ||||||
|  ifdef CONFIG_CODE_COVERAGE |  | ||||||
|  CFLAGS += -O0 -fprofile-arcs -ftest-coverage |  | ||||||
| --- a/src/ap/hostapd.h |  | ||||||
| +++ b/src/ap/hostapd.h |  | ||||||
| @@ -18,6 +18,7 @@ |  | ||||||
|  #include "utils/list.h" |  | ||||||
|  #include "ap_config.h" |  | ||||||
|  #include "drivers/driver.h" |  | ||||||
| +#include "ubus.h" |  | ||||||
|   |  | ||||||
|  #define OCE_STA_CFON_ENABLED(hapd) \ |  | ||||||
|  	((hapd->conf->oce & OCE_STA_CFON) && \ |  | ||||||
| @@ -184,6 +185,7 @@ struct hostapd_data { |  | ||||||
|  	struct hostapd_iface *iface; |  | ||||||
|  	struct hostapd_config *iconf; |  | ||||||
|  	struct hostapd_bss_config *conf; |  | ||||||
| +	struct hostapd_ubus_bss ubus; |  | ||||||
|  	int interface_added; /* virtual interface added for this BSS */ |  | ||||||
|  	unsigned int started:1; |  | ||||||
|  	unsigned int disabled:1; |  | ||||||
| @@ -695,6 +697,7 @@ hostapd_alloc_bss_data(struct hostapd_if |  | ||||||
|  		       struct hostapd_bss_config *bss); |  | ||||||
|  int hostapd_setup_interface(struct hostapd_iface *iface); |  | ||||||
|  int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err); |  | ||||||
| +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd); |  | ||||||
|  void hostapd_interface_deinit(struct hostapd_iface *iface); |  | ||||||
|  void hostapd_interface_free(struct hostapd_iface *iface); |  | ||||||
|  struct hostapd_iface * hostapd_alloc_iface(void); |  | ||||||
| --- a/src/ap/hostapd.c |  | ||||||
| +++ b/src/ap/hostapd.c |  | ||||||
| @@ -435,6 +435,7 @@ void hostapd_free_hapd_data(struct hosta |  | ||||||
|  	hapd->beacon_set_done = 0; |  | ||||||
|   |  | ||||||
|  	wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface); |  | ||||||
| +	hostapd_ubus_free_bss(hapd); |  | ||||||
|  	accounting_deinit(hapd); |  | ||||||
|  	hostapd_deinit_wpa(hapd); |  | ||||||
|  	vlan_deinit(hapd); |  | ||||||
| @@ -1187,6 +1188,8 @@ static int hostapd_start_beacon(struct h |  | ||||||
|  	if (hapd->driver && hapd->driver->set_operstate) |  | ||||||
|  		hapd->driver->set_operstate(hapd->drv_priv, 1); |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_add_bss(hapd); |  | ||||||
| + |  | ||||||
|  	return 0; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| @@ -2275,6 +2278,7 @@ static int hostapd_setup_interface_compl |  | ||||||
|  	if (err) |  | ||||||
|  		goto fail; |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_add_iface(iface); |  | ||||||
|  	wpa_printf(MSG_DEBUG, "Completing interface initialization"); |  | ||||||
|  	if (iface->freq) { |  | ||||||
|  #ifdef NEED_AP_MLME |  | ||||||
| @@ -2494,6 +2498,7 @@ dfs_offload: |  | ||||||
|   |  | ||||||
|  fail: |  | ||||||
|  	wpa_printf(MSG_ERROR, "Interface initialization failed"); |  | ||||||
| +	hostapd_ubus_free_iface(iface); |  | ||||||
|   |  | ||||||
|  	if (iface->is_no_ir) { |  | ||||||
|  		hostapd_set_state(iface, HAPD_IFACE_NO_IR); |  | ||||||
| @@ -2984,6 +2989,7 @@ void hostapd_interface_deinit_free(struc |  | ||||||
|  		   (unsigned int) iface->conf->num_bss); |  | ||||||
|  	driver = iface->bss[0]->driver; |  | ||||||
|  	drv_priv = iface->bss[0]->drv_priv; |  | ||||||
| +	hostapd_ubus_free_iface(iface); |  | ||||||
|  	hostapd_interface_deinit(iface); |  | ||||||
|  	wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", |  | ||||||
|  		   __func__, driver, drv_priv); |  | ||||||
| --- a/src/ap/ieee802_11.c |  | ||||||
| +++ b/src/ap/ieee802_11.c |  | ||||||
| @@ -2786,7 +2786,7 @@ static void handle_auth(struct hostapd_d |  | ||||||
|  	u16 auth_alg, auth_transaction, status_code; |  | ||||||
|  	u16 resp = WLAN_STATUS_SUCCESS; |  | ||||||
|  	struct sta_info *sta = NULL; |  | ||||||
| -	int res, reply_res; |  | ||||||
| +	int res, reply_res, ubus_resp; |  | ||||||
|  	u16 fc; |  | ||||||
|  	const u8 *challenge = NULL; |  | ||||||
|  	u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |  | ||||||
| @@ -2795,6 +2795,11 @@ static void handle_auth(struct hostapd_d |  | ||||||
|  	struct radius_sta rad_info; |  | ||||||
|  	const u8 *dst, *sa, *bssid; |  | ||||||
|  	bool mld_sta = false; |  | ||||||
| +	struct hostapd_ubus_request req = { |  | ||||||
| +		.type = HOSTAPD_UBUS_AUTH_REQ, |  | ||||||
| +		.mgmt_frame = mgmt, |  | ||||||
| +		.ssi_signal = rssi, |  | ||||||
| +	}; |  | ||||||
|   |  | ||||||
|  	if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |  | ||||||
|  		wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |  | ||||||
| @@ -2986,6 +2991,13 @@ static void handle_auth(struct hostapd_d |  | ||||||
|  		resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
|  		goto fail; |  | ||||||
|  	} |  | ||||||
| +	ubus_resp = hostapd_ubus_handle_event(hapd, &req); |  | ||||||
| +	if (0 && ubus_resp) { |  | ||||||
| +		wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n", |  | ||||||
| +			MAC2STR(mgmt->sa)); |  | ||||||
| +		resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
| +		goto fail; |  | ||||||
| +	} |  | ||||||
|  	if (res == HOSTAPD_ACL_PENDING) |  | ||||||
|  		return; |  | ||||||
|   |  | ||||||
| @@ -5161,7 +5173,7 @@ static void handle_assoc(struct hostapd_ |  | ||||||
|  	int resp = WLAN_STATUS_SUCCESS; |  | ||||||
|  	u16 reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
|  	const u8 *pos; |  | ||||||
| -	int left, i; |  | ||||||
| +	int left, i, ubus_resp; |  | ||||||
|  	struct sta_info *sta; |  | ||||||
|  	u8 *tmp = NULL; |  | ||||||
|  #ifdef CONFIG_FILS |  | ||||||
| @@ -5374,6 +5386,11 @@ static void handle_assoc(struct hostapd_ |  | ||||||
|  		left = res; |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_FILS */ |  | ||||||
| +	struct hostapd_ubus_request req = { |  | ||||||
| +		.type = HOSTAPD_UBUS_ASSOC_REQ, |  | ||||||
| +		.mgmt_frame = mgmt, |  | ||||||
| +		.ssi_signal = rssi, |  | ||||||
| +	}; |  | ||||||
|   |  | ||||||
|  	/* followed by SSID and Supported rates; and HT capabilities if 802.11n |  | ||||||
|  	 * is used */ |  | ||||||
| @@ -5472,6 +5489,13 @@ static void handle_assoc(struct hostapd_ |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_FILS */ |  | ||||||
|   |  | ||||||
| +	ubus_resp = hostapd_ubus_handle_event(hapd, &req); |  | ||||||
| +	if (0 && ubus_resp) { |  | ||||||
| +		wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n", |  | ||||||
| +		       MAC2STR(mgmt->sa)); |  | ||||||
| +		resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
| +		goto fail; |  | ||||||
| +	} |  | ||||||
|   fail: |  | ||||||
|   |  | ||||||
|  	/* |  | ||||||
| @@ -5753,6 +5777,7 @@ static void handle_disassoc(struct hosta |  | ||||||
|  			   (unsigned long) len); |  | ||||||
|  		return; |  | ||||||
|  	} |  | ||||||
| +	hostapd_ubus_notify(hapd, "disassoc", mgmt->sa); |  | ||||||
|   |  | ||||||
|  	sta = ap_get_sta(hapd, mgmt->sa); |  | ||||||
|  	if (!sta) { |  | ||||||
| @@ -5784,6 +5809,8 @@ static void handle_deauth(struct hostapd |  | ||||||
|  	/* Clear the PTKSA cache entries for PASN */ |  | ||||||
|  	ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE); |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_notify(hapd, "deauth", mgmt->sa); |  | ||||||
| + |  | ||||||
|  	sta = ap_get_sta(hapd, mgmt->sa); |  | ||||||
|  	if (!sta) { |  | ||||||
|  		wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |  | ||||||
| --- a/src/ap/beacon.c |  | ||||||
| +++ b/src/ap/beacon.c |  | ||||||
| @@ -1036,6 +1036,12 @@ void handle_probe_req(struct hostapd_dat |  | ||||||
|  	u16 csa_offs[2]; |  | ||||||
|  	size_t csa_offs_len; |  | ||||||
|  	struct radius_sta rad_info; |  | ||||||
| +	struct hostapd_ubus_request req = { |  | ||||||
| +		.type = HOSTAPD_UBUS_PROBE_REQ, |  | ||||||
| +		.mgmt_frame = mgmt, |  | ||||||
| +		.ssi_signal = ssi_signal, |  | ||||||
| +		.elems = &elems, |  | ||||||
| +	}; |  | ||||||
|   |  | ||||||
|  	if (hapd->iconf->rssi_ignore_probe_request && ssi_signal && |  | ||||||
|  	    ssi_signal < hapd->iconf->rssi_ignore_probe_request) |  | ||||||
| @@ -1222,6 +1228,12 @@ void handle_probe_req(struct hostapd_dat |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_P2P */ |  | ||||||
|   |  | ||||||
| +	if (hostapd_ubus_handle_event(hapd, &req)) { |  | ||||||
| +		wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n", |  | ||||||
| +		       MAC2STR(mgmt->sa)); |  | ||||||
| +		return; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
|  	/* TODO: verify that supp_rates contains at least one matching rate |  | ||||||
|  	 * with AP configuration */ |  | ||||||
|   |  | ||||||
| --- a/src/ap/drv_callbacks.c |  | ||||||
| +++ b/src/ap/drv_callbacks.c |  | ||||||
| @@ -260,6 +260,10 @@ int hostapd_notif_assoc(struct hostapd_d |  | ||||||
|  	u16 reason = WLAN_REASON_UNSPECIFIED; |  | ||||||
|  	int status = WLAN_STATUS_SUCCESS; |  | ||||||
|  	const u8 *p2p_dev_addr = NULL; |  | ||||||
| +	struct hostapd_ubus_request req = { |  | ||||||
| +		.type = HOSTAPD_UBUS_ASSOC_REQ, |  | ||||||
| +		.addr = addr, |  | ||||||
| +	}; |  | ||||||
|   |  | ||||||
|  	if (addr == NULL) { |  | ||||||
|  		/* |  | ||||||
| @@ -396,6 +400,12 @@ int hostapd_notif_assoc(struct hostapd_d |  | ||||||
|  		goto fail; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	if (hostapd_ubus_handle_event(hapd, &req)) { |  | ||||||
| +		wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n", |  | ||||||
| +			   MAC2STR(req.addr)); |  | ||||||
| +		goto fail; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
|  #ifdef CONFIG_P2P |  | ||||||
|  	if (elems.p2p) { |  | ||||||
|  		wpabuf_free(sta->p2p_ie); |  | ||||||
| --- a/src/ap/sta_info.c |  | ||||||
| +++ b/src/ap/sta_info.c |  | ||||||
| @@ -471,6 +471,7 @@ void ap_handle_timer(void *eloop_ctx, vo |  | ||||||
|  		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |  | ||||||
|  			       HOSTAPD_LEVEL_INFO, "deauthenticated due to " |  | ||||||
|  			       "local deauth request"); |  | ||||||
| +		hostapd_ubus_notify(hapd, "local-deauth", sta->addr); |  | ||||||
|  		ap_free_sta(hapd, sta); |  | ||||||
|  		return; |  | ||||||
|  	} |  | ||||||
| @@ -626,6 +627,7 @@ skip_poll: |  | ||||||
|  		mlme_deauthenticate_indication( |  | ||||||
|  			hapd, sta, |  | ||||||
|  			WLAN_REASON_PREV_AUTH_NOT_VALID); |  | ||||||
| +		hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr); |  | ||||||
|  		ap_free_sta(hapd, sta); |  | ||||||
|  		break; |  | ||||||
|  	} |  | ||||||
| @@ -1344,15 +1346,28 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  					sta->addr, authorized, dev_addr); |  | ||||||
|   |  | ||||||
|  	if (authorized) { |  | ||||||
| +		static const char * const auth_algs[] = { |  | ||||||
| +			[WLAN_AUTH_OPEN] = "open", |  | ||||||
| +			[WLAN_AUTH_SHARED_KEY] = "shared", |  | ||||||
| +			[WLAN_AUTH_FT] = "ft", |  | ||||||
| +			[WLAN_AUTH_SAE] = "sae", |  | ||||||
| +			[WLAN_AUTH_FILS_SK] = "fils-sk", |  | ||||||
| +			[WLAN_AUTH_FILS_SK_PFS] = "fils-sk-pfs", |  | ||||||
| +			[WLAN_AUTH_FILS_PK] = "fils-pk", |  | ||||||
| +			[WLAN_AUTH_PASN] = "pasn", |  | ||||||
| +		}; |  | ||||||
| +		const char *auth_alg = NULL; |  | ||||||
|  		const u8 *dpp_pkhash; |  | ||||||
|  		const char *keyid; |  | ||||||
|  		char dpp_pkhash_buf[100]; |  | ||||||
|  		char keyid_buf[100]; |  | ||||||
|  		char ip_addr[100]; |  | ||||||
| +		char alg_buf[100]; |  | ||||||
|   |  | ||||||
|  		dpp_pkhash_buf[0] = '\0'; |  | ||||||
|  		keyid_buf[0] = '\0'; |  | ||||||
|  		ip_addr[0] = '\0'; |  | ||||||
| +		alg_buf[0] = '\0'; |  | ||||||
|  #ifdef CONFIG_P2P |  | ||||||
|  		if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) { |  | ||||||
|  			os_snprintf(ip_addr, sizeof(ip_addr), |  | ||||||
| @@ -1362,6 +1377,13 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  		} |  | ||||||
|  #endif /* CONFIG_P2P */ |  | ||||||
|   |  | ||||||
| +		if (sta->auth_alg < ARRAY_SIZE(auth_algs)) |  | ||||||
| +			auth_alg = auth_algs[sta->auth_alg]; |  | ||||||
| + |  | ||||||
| +		if (auth_alg) |  | ||||||
| +			os_snprintf(alg_buf, sizeof(alg_buf), |  | ||||||
| +				" auth_alg=%s", auth_alg); |  | ||||||
| + |  | ||||||
|  		keyid = ap_sta_wpa_get_keyid(hapd, sta); |  | ||||||
|  		if (keyid) { |  | ||||||
|  			os_snprintf(keyid_buf, sizeof(keyid_buf), |  | ||||||
| @@ -1380,17 +1402,19 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  					 dpp_pkhash, SHA256_MAC_LEN); |  | ||||||
|  		} |  | ||||||
|   |  | ||||||
| -		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s", |  | ||||||
| -			buf, ip_addr, keyid_buf, dpp_pkhash_buf); |  | ||||||
| +		hostapd_ubus_notify_authorized(hapd, sta); |  | ||||||
| +		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s%s", |  | ||||||
| +			buf, ip_addr, keyid_buf, dpp_pkhash_buf, alg_buf); |  | ||||||
|   |  | ||||||
|  		if (hapd->msg_ctx_parent && |  | ||||||
|  		    hapd->msg_ctx_parent != hapd->msg_ctx) |  | ||||||
|  			wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |  | ||||||
| -					  AP_STA_CONNECTED "%s%s%s%s", |  | ||||||
| +					  AP_STA_CONNECTED "%s%s%s%s%s", |  | ||||||
|  					  buf, ip_addr, keyid_buf, |  | ||||||
| -					  dpp_pkhash_buf); |  | ||||||
| +					  dpp_pkhash_buf, alg_buf); |  | ||||||
|  	} else { |  | ||||||
|  		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |  | ||||||
| +		hostapd_ubus_notify(hapd, "disassoc", sta->addr); |  | ||||||
|   |  | ||||||
|  		if (hapd->msg_ctx_parent && |  | ||||||
|  		    hapd->msg_ctx_parent != hapd->msg_ctx) |  | ||||||
| --- a/src/ap/wpa_auth_glue.c |  | ||||||
| +++ b/src/ap/wpa_auth_glue.c |  | ||||||
| @@ -269,6 +269,7 @@ static void hostapd_wpa_auth_psk_failure |  | ||||||
|  	struct hostapd_data *hapd = ctx; |  | ||||||
|  	wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR, |  | ||||||
|  		MAC2STR(addr)); |  | ||||||
| +	hostapd_ubus_notify(hapd, "key-mismatch", addr); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| --- a/wpa_supplicant/Makefile |  | ||||||
| +++ b/wpa_supplicant/Makefile |  | ||||||
| @@ -192,6 +192,13 @@ ifdef CONFIG_EAPOL_TEST |  | ||||||
|  CFLAGS += -Werror -DEAPOL_TEST |  | ||||||
|  endif |  | ||||||
|   |  | ||||||
| +ifdef CONFIG_UBUS |  | ||||||
| +CFLAGS += -DUBUS_SUPPORT |  | ||||||
| +OBJS += ubus.o |  | ||||||
| +OBJS += ../src/utils/uloop.o |  | ||||||
| +LIBS += -lubox -lubus |  | ||||||
| +endif |  | ||||||
| + |  | ||||||
|  ifdef CONFIG_CODE_COVERAGE |  | ||||||
|  CFLAGS += -O0 -fprofile-arcs -ftest-coverage |  | ||||||
|  LIBS += -lgcov |  | ||||||
| @@ -987,6 +994,9 @@ ifdef CONFIG_CTRL_IFACE_MIB |  | ||||||
|  CFLAGS += -DCONFIG_CTRL_IFACE_MIB |  | ||||||
|  endif |  | ||||||
|  OBJS += ../src/ap/ctrl_iface_ap.o |  | ||||||
| +ifdef CONFIG_UBUS |  | ||||||
| +OBJS += ../src/ap/ubus.o |  | ||||||
| +endif |  | ||||||
|  endif |  | ||||||
|   |  | ||||||
|  CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY |  | ||||||
| --- a/wpa_supplicant/wpa_supplicant.c |  | ||||||
| +++ b/wpa_supplicant/wpa_supplicant.c |  | ||||||
| @@ -7593,6 +7593,8 @@ struct wpa_supplicant * wpa_supplicant_a |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_P2P */ |  | ||||||
|   |  | ||||||
| +	wpas_ubus_add_bss(wpa_s); |  | ||||||
| + |  | ||||||
|  	return wpa_s; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| @@ -7619,6 +7621,8 @@ int wpa_supplicant_remove_iface(struct w |  | ||||||
|  	struct wpa_supplicant *parent = wpa_s->parent; |  | ||||||
|  #endif /* CONFIG_MESH */ |  | ||||||
|   |  | ||||||
| +	wpas_ubus_free_bss(wpa_s); |  | ||||||
| + |  | ||||||
|  	/* Remove interface from the global list of interfaces */ |  | ||||||
|  	prev = global->ifaces; |  | ||||||
|  	if (prev == wpa_s) { |  | ||||||
| @@ -7965,8 +7969,12 @@ int wpa_supplicant_run(struct wpa_global |  | ||||||
|  	eloop_register_signal_terminate(wpa_supplicant_terminate, global); |  | ||||||
|  	eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); |  | ||||||
|   |  | ||||||
| +	wpas_ubus_add(global); |  | ||||||
| + |  | ||||||
|  	eloop_run(); |  | ||||||
|   |  | ||||||
| +	wpas_ubus_free(global); |  | ||||||
| + |  | ||||||
|  	return 0; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| --- a/wpa_supplicant/wpa_supplicant_i.h |  | ||||||
| +++ b/wpa_supplicant/wpa_supplicant_i.h |  | ||||||
| @@ -21,6 +21,7 @@ |  | ||||||
|  #include "config_ssid.h" |  | ||||||
|  #include "wmm_ac.h" |  | ||||||
|  #include "pasn/pasn_common.h" |  | ||||||
| +#include "ubus.h" |  | ||||||
|   |  | ||||||
|  extern const char *const wpa_supplicant_version; |  | ||||||
|  extern const char *const wpa_supplicant_license; |  | ||||||
| @@ -319,6 +320,8 @@ struct wpa_global { |  | ||||||
|  #endif /* CONFIG_WIFI_DISPLAY */ |  | ||||||
|   |  | ||||||
|  	struct psk_list_entry *add_psk; /* From group formation */ |  | ||||||
| + |  | ||||||
| +	struct ubus_object ubus_global; |  | ||||||
|  }; |  | ||||||
|   |  | ||||||
|   |  | ||||||
| @@ -685,6 +688,7 @@ struct wpa_supplicant { |  | ||||||
|  	unsigned char own_addr[ETH_ALEN]; |  | ||||||
|  	unsigned char perm_addr[ETH_ALEN]; |  | ||||||
|  	char ifname[100]; |  | ||||||
| +	struct wpas_ubus_bss ubus; |  | ||||||
|  #ifdef CONFIG_MATCH_IFACE |  | ||||||
|  	int matched; |  | ||||||
|  #endif /* CONFIG_MATCH_IFACE */ |  | ||||||
| --- a/wpa_supplicant/wps_supplicant.c |  | ||||||
| +++ b/wpa_supplicant/wps_supplicant.c |  | ||||||
| @@ -33,6 +33,7 @@ |  | ||||||
|  #include "p2p/p2p.h" |  | ||||||
|  #include "p2p_supplicant.h" |  | ||||||
|  #include "wps_supplicant.h" |  | ||||||
| +#include "ubus.h" |  | ||||||
|   |  | ||||||
|   |  | ||||||
|  #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG |  | ||||||
| @@ -402,6 +403,8 @@ static int wpa_supplicant_wps_cred(void |  | ||||||
|  	wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute", |  | ||||||
|  			cred->cred_attr, cred->cred_attr_len); |  | ||||||
|   |  | ||||||
| +	wpas_ubus_notify(wpa_s, cred); |  | ||||||
| + |  | ||||||
|  	if (wpa_s->conf->wps_cred_processing == 1) |  | ||||||
|  		return 0; |  | ||||||
|   |  | ||||||
| --- a/wpa_supplicant/main.c |  | ||||||
| +++ b/wpa_supplicant/main.c |  | ||||||
| @@ -203,7 +203,7 @@ int main(int argc, char *argv[]) |  | ||||||
|   |  | ||||||
|  	for (;;) { |  | ||||||
|  		c = getopt(argc, argv, |  | ||||||
| -			   "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuv::W"); |  | ||||||
| +			   "b:Bc:C:D:de:f:g:G:hi:I:KLMm:nNo:O:p:P:qsTtuv::W"); |  | ||||||
|  		if (c < 0) |  | ||||||
|  			break; |  | ||||||
|  		switch (c) { |  | ||||||
| @@ -268,6 +268,9 @@ int main(int argc, char *argv[]) |  | ||||||
|  			params.conf_p2p_dev = optarg; |  | ||||||
|  			break; |  | ||||||
|  #endif /* CONFIG_P2P */ |  | ||||||
| +		case 'n': |  | ||||||
| +			iface_count = 0; |  | ||||||
| +			break; |  | ||||||
|  		case 'o': |  | ||||||
|  			params.override_driver = optarg; |  | ||||||
|  			break; |  | ||||||
| --- a/src/ap/rrm.c |  | ||||||
| +++ b/src/ap/rrm.c |  | ||||||
| @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report |  | ||||||
|  		return; |  | ||||||
|  	wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s", |  | ||||||
|  		MAC2STR(addr), token, rep_mode, report); |  | ||||||
| +	if (len < sizeof(struct rrm_measurement_beacon_report)) |  | ||||||
| +		return; |  | ||||||
| +	hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| --- a/src/ap/vlan_init.c |  | ||||||
| +++ b/src/ap/vlan_init.c |  | ||||||
| @@ -22,6 +22,7 @@ |  | ||||||
|  static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, |  | ||||||
|  		       int existsok) |  | ||||||
|  { |  | ||||||
| +	bool vlan_exists = iface_exists(vlan->ifname); |  | ||||||
|  	int ret; |  | ||||||
|  #ifdef CONFIG_WEP |  | ||||||
|  	int i; |  | ||||||
| @@ -36,7 +37,7 @@ static int vlan_if_add(struct hostapd_da |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_WEP */ |  | ||||||
|   |  | ||||||
| -	if (!iface_exists(vlan->ifname)) |  | ||||||
| +	if (!vlan_exists) |  | ||||||
|  		ret = hostapd_vlan_if_add(hapd, vlan->ifname); |  | ||||||
|  	else if (!existsok) |  | ||||||
|  		return -1; |  | ||||||
| @@ -51,6 +52,9 @@ static int vlan_if_add(struct hostapd_da |  | ||||||
|  	if (hapd->wpa_auth) |  | ||||||
|  		ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id); |  | ||||||
|   |  | ||||||
| +	if (!ret && !vlan_exists) |  | ||||||
| +		hostapd_ubus_add_vlan(hapd, vlan); |  | ||||||
| + |  | ||||||
|  	if (ret == 0) |  | ||||||
|  		return ret; |  | ||||||
|   |  | ||||||
| @@ -77,6 +81,8 @@ int vlan_if_remove(struct hostapd_data * |  | ||||||
|  			   "WPA deinitialization for VLAN %d failed (%d)", |  | ||||||
|  			   vlan->vlan_id, ret); |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_remove_vlan(hapd, vlan); |  | ||||||
| + |  | ||||||
|  	return hostapd_vlan_if_remove(hapd, vlan->ifname); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| --- a/src/ap/dfs.c |  | ||||||
| +++ b/src/ap/dfs.c |  | ||||||
| @@ -1216,6 +1216,8 @@ int hostapd_dfs_pre_cac_expired(struct h |  | ||||||
|  		"freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", |  | ||||||
|  		freq, ht_enabled, chan_offset, chan_width, cf1, cf2); |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_notify_radar_detected(iface, freq, chan_width, cf1, cf2); |  | ||||||
| + |  | ||||||
|  	/* Proceed only if DFS is not offloaded to the driver */ |  | ||||||
|  	if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) |  | ||||||
|  		return 0; |  | ||||||
| --- a/src/ap/airtime_policy.c |  | ||||||
| +++ b/src/ap/airtime_policy.c |  | ||||||
| @@ -112,8 +112,14 @@ static void set_sta_weights(struct hosta |  | ||||||
|  { |  | ||||||
|  	struct sta_info *sta; |  | ||||||
|   |  | ||||||
| -	for (sta = hapd->sta_list; sta; sta = sta->next) |  | ||||||
| -		sta_set_airtime_weight(hapd, sta, weight); |  | ||||||
| +	for (sta = hapd->sta_list; sta; sta = sta->next) { |  | ||||||
| +		unsigned int sta_weight = weight; |  | ||||||
| + |  | ||||||
| +		if (sta->dyn_airtime_weight) |  | ||||||
| +			sta_weight = (weight * sta->dyn_airtime_weight) / 256; |  | ||||||
| + |  | ||||||
| +		sta_set_airtime_weight(hapd, sta, sta_weight); |  | ||||||
| +	} |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| @@ -244,7 +250,10 @@ int airtime_policy_new_sta(struct hostap |  | ||||||
|  	unsigned int weight; |  | ||||||
|   |  | ||||||
|  	if (hapd->iconf->airtime_mode == AIRTIME_MODE_STATIC) { |  | ||||||
| -		weight = get_weight_for_sta(hapd, sta->addr); |  | ||||||
| +		if (sta->dyn_airtime_weight) |  | ||||||
| +			weight = sta->dyn_airtime_weight; |  | ||||||
| +		else |  | ||||||
| +			weight = get_weight_for_sta(hapd, sta->addr); |  | ||||||
|  		if (weight) |  | ||||||
|  			return sta_set_airtime_weight(hapd, sta, weight); |  | ||||||
|  	} |  | ||||||
| --- a/src/ap/sta_info.h |  | ||||||
| +++ b/src/ap/sta_info.h |  | ||||||
| @@ -322,6 +322,7 @@ struct sta_info { |  | ||||||
|  #endif /* CONFIG_TESTING_OPTIONS */ |  | ||||||
|  #ifdef CONFIG_AIRTIME_POLICY |  | ||||||
|  	unsigned int airtime_weight; |  | ||||||
| +	unsigned int dyn_airtime_weight; |  | ||||||
|  	struct os_reltime backlogged_until; |  | ||||||
|  #endif /* CONFIG_AIRTIME_POLICY */ |  | ||||||
|   |  | ||||||
| --- a/src/ap/wnm_ap.c |  | ||||||
| +++ b/src/ap/wnm_ap.c |  | ||||||
| @@ -455,7 +455,8 @@ static void ieee802_11_rx_bss_trans_mgmt |  | ||||||
|  		MAC2STR(addr), reason, hex ? " neighbor=" : "", hex); |  | ||||||
|  	os_free(hex); |  | ||||||
|   |  | ||||||
| -	ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token); |  | ||||||
| +	if (!hostapd_ubus_notify_bss_transition_query(hapd, addr, dialog_token, reason, pos, end - pos)) |  | ||||||
| +		ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| @@ -477,7 +478,7 @@ static void ieee802_11_rx_bss_trans_mgmt |  | ||||||
|  					      size_t len) |  | ||||||
|  { |  | ||||||
|  	u8 dialog_token, status_code, bss_termination_delay; |  | ||||||
| -	const u8 *pos, *end; |  | ||||||
| +	const u8 *pos, *end, *target_bssid = NULL; |  | ||||||
|  	int enabled = hapd->conf->bss_transition; |  | ||||||
|  	struct sta_info *sta; |  | ||||||
|   |  | ||||||
| @@ -524,6 +525,7 @@ static void ieee802_11_rx_bss_trans_mgmt |  | ||||||
|  			wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field"); |  | ||||||
|  			return; |  | ||||||
|  		} |  | ||||||
| +		target_bssid = pos; |  | ||||||
|  		sta->agreed_to_steer = 1; |  | ||||||
|  		eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta); |  | ||||||
|  		eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer, |  | ||||||
| @@ -543,6 +545,10 @@ static void ieee802_11_rx_bss_trans_mgmt |  | ||||||
|  			MAC2STR(addr), status_code, bss_termination_delay); |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	hostapd_ubus_notify_bss_transition_response(hapd, sta->addr, dialog_token, |  | ||||||
| +						    status_code, bss_termination_delay, |  | ||||||
| +						    target_bssid, pos, end - pos); |  | ||||||
| + |  | ||||||
|  	wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries", |  | ||||||
|  		    pos, end - pos); |  | ||||||
|  } |  | ||||||
| --- a/src/utils/eloop.c |  | ||||||
| +++ b/src/utils/eloop.c |  | ||||||
| @@ -77,6 +77,9 @@ struct eloop_sock_table { |  | ||||||
|  struct eloop_data { |  | ||||||
|  	int max_sock; |  | ||||||
|   |  | ||||||
| +	eloop_timeout_poll_handler timeout_poll_cb; |  | ||||||
| +	eloop_poll_handler poll_cb; |  | ||||||
| + |  | ||||||
|  	size_t count; /* sum of all table counts */ |  | ||||||
|  #ifdef CONFIG_ELOOP_POLL |  | ||||||
|  	size_t max_pollfd_map; /* number of pollfds_map currently allocated */ |  | ||||||
| @@ -1121,6 +1124,12 @@ void eloop_run(void) |  | ||||||
|  				os_reltime_sub(&timeout->time, &now, &tv); |  | ||||||
|  			else |  | ||||||
|  				tv.sec = tv.usec = 0; |  | ||||||
| +		} |  | ||||||
| + |  | ||||||
| +		if (eloop.timeout_poll_cb && eloop.timeout_poll_cb(&tv, !!timeout)) |  | ||||||
| +			timeout = (void *)1; |  | ||||||
| + |  | ||||||
| +		if (timeout) { |  | ||||||
|  #if defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL) |  | ||||||
|  			timeout_ms = tv.sec * 1000 + tv.usec / 1000; |  | ||||||
|  #endif /* defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL) */ |  | ||||||
| @@ -1190,7 +1199,8 @@ void eloop_run(void) |  | ||||||
|  		eloop.exceptions.changed = 0; |  | ||||||
|   |  | ||||||
|  		eloop_process_pending_signals(); |  | ||||||
| - |  | ||||||
| +		if (eloop.poll_cb) |  | ||||||
| +			eloop.poll_cb(); |  | ||||||
|   |  | ||||||
|  		/* check if some registered timeouts have occurred */ |  | ||||||
|  		timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, |  | ||||||
| @@ -1252,6 +1262,14 @@ out: |  | ||||||
|  	return; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| +int eloop_register_cb(eloop_poll_handler poll_cb, |  | ||||||
| +		      eloop_timeout_poll_handler timeout_cb) |  | ||||||
| +{ |  | ||||||
| +	eloop.poll_cb = poll_cb; |  | ||||||
| +	eloop.timeout_poll_cb = timeout_cb; |  | ||||||
| + |  | ||||||
| +	return 0; |  | ||||||
| +} |  | ||||||
|   |  | ||||||
|  void eloop_terminate(void) |  | ||||||
|  { |  | ||||||
| --- a/src/utils/eloop.h |  | ||||||
| +++ b/src/utils/eloop.h |  | ||||||
| @@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo |  | ||||||
|   */ |  | ||||||
|  typedef void (*eloop_signal_handler)(int sig, void *signal_ctx); |  | ||||||
|   |  | ||||||
| +typedef bool (*eloop_timeout_poll_handler)(struct os_reltime *tv, bool tv_set); |  | ||||||
| +typedef void (*eloop_poll_handler)(void); |  | ||||||
| + |  | ||||||
|  /** |  | ||||||
|   * eloop_init() - Initialize global event loop data |  | ||||||
|   * Returns: 0 on success, -1 on failure |  | ||||||
| @@ -73,6 +76,9 @@ typedef void (*eloop_signal_handler)(int |  | ||||||
|   */ |  | ||||||
|  int eloop_init(void); |  | ||||||
|   |  | ||||||
| +int eloop_register_cb(eloop_poll_handler poll_cb, |  | ||||||
| +		      eloop_timeout_poll_handler timeout_cb); |  | ||||||
| + |  | ||||||
|  /** |  | ||||||
|   * eloop_register_read_sock - Register handler for read events |  | ||||||
|   * @sock: File descriptor number for the socket |  | ||||||
| @@ -320,6 +326,8 @@ int eloop_register_signal_reconfig(eloop |  | ||||||
|   */ |  | ||||||
|  int eloop_sock_requeue(void); |  | ||||||
|   |  | ||||||
| +void eloop_add_uloop(void); |  | ||||||
| + |  | ||||||
|  /** |  | ||||||
|   * eloop_run - Start the event loop |  | ||||||
|   * |  | ||||||
| --- /dev/null |  | ||||||
| +++ b/src/utils/uloop.c |  | ||||||
| @@ -0,0 +1,64 @@ |  | ||||||
| +#include <libubox/uloop.h> |  | ||||||
| +#include "includes.h" |  | ||||||
| +#include "common.h" |  | ||||||
| +#include "eloop.h" |  | ||||||
| + |  | ||||||
| +static void eloop_uloop_event_cb(int sock, void *eloop_ctx, void *sock_ctx) |  | ||||||
| +{ |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| +static void eloop_uloop_fd_cb(struct uloop_fd *fd, unsigned int events) |  | ||||||
| +{ |  | ||||||
| +	unsigned int changed = events ^ fd->flags; |  | ||||||
| + |  | ||||||
| +	if (changed & ULOOP_READ) { |  | ||||||
| +		if (events & ULOOP_READ) |  | ||||||
| +			eloop_register_sock(fd->fd, EVENT_TYPE_READ, eloop_uloop_event_cb, fd, fd); |  | ||||||
| +		else |  | ||||||
| +			eloop_unregister_sock(fd->fd, EVENT_TYPE_READ); |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	if (changed & ULOOP_WRITE) { |  | ||||||
| +		if (events & ULOOP_WRITE) |  | ||||||
| +			eloop_register_sock(fd->fd, EVENT_TYPE_WRITE, eloop_uloop_event_cb, fd, fd); |  | ||||||
| +		else |  | ||||||
| +			eloop_unregister_sock(fd->fd, EVENT_TYPE_WRITE); |  | ||||||
| +	} |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| +static bool uloop_timeout_poll_handler(struct os_reltime *tv, bool tv_set) |  | ||||||
| +{ |  | ||||||
| +	struct os_reltime tv_uloop; |  | ||||||
| +	int timeout_ms = uloop_get_next_timeout(); |  | ||||||
| + |  | ||||||
| +	if (timeout_ms < 0) |  | ||||||
| +		return false; |  | ||||||
| + |  | ||||||
| +	tv_uloop.sec = timeout_ms / 1000; |  | ||||||
| +	tv_uloop.usec = (timeout_ms % 1000) * 1000; |  | ||||||
| + |  | ||||||
| +	if (!tv_set || os_reltime_before(&tv_uloop, tv)) { |  | ||||||
| +		*tv = tv_uloop; |  | ||||||
| +		return true; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	return false; |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| +static void uloop_poll_handler(void) |  | ||||||
| +{ |  | ||||||
| +	uloop_run_timeout(0); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| +void eloop_add_uloop(void) |  | ||||||
| +{ |  | ||||||
| +	static bool init_done = false; |  | ||||||
| + |  | ||||||
| +	if (!init_done) { |  | ||||||
| +		uloop_init(); |  | ||||||
| +		uloop_fd_set_cb = eloop_uloop_fd_cb; |  | ||||||
| +		init_done = true; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	eloop_register_cb(uloop_poll_handler, uloop_timeout_poll_handler); |  | ||||||
| +} |  | ||||||
| @@ -1,723 +0,0 @@ | |||||||
| --- a/hostapd/Makefile |  | ||||||
| +++ b/hostapd/Makefile |  | ||||||
| @@ -168,9 +168,21 @@ OBJS += ../src/eapol_auth/eapol_auth_sm. |  | ||||||
|   |  | ||||||
|  ifdef CONFIG_UBUS |  | ||||||
|  CFLAGS += -DUBUS_SUPPORT |  | ||||||
| -OBJS += ../src/utils/uloop.o |  | ||||||
|  OBJS += ../src/ap/ubus.o |  | ||||||
| -LIBS += -lubox -lubus |  | ||||||
| +LIBS += -lubus |  | ||||||
| +NEED_ULOOP:=y |  | ||||||
| +endif |  | ||||||
| + |  | ||||||
| +ifdef CONFIG_UCODE |  | ||||||
| +CFLAGS += -DUCODE_SUPPORT |  | ||||||
| +OBJS += ../src/utils/ucode.o |  | ||||||
| +OBJS += ../src/ap/ucode.o |  | ||||||
| +NEED_ULOOP:=y |  | ||||||
| +endif |  | ||||||
| + |  | ||||||
| +ifdef NEED_ULOOP |  | ||||||
| +OBJS += ../src/utils/uloop.o |  | ||||||
| +LIBS += -lubox |  | ||||||
|  endif |  | ||||||
|   |  | ||||||
|  ifdef CONFIG_CODE_COVERAGE |  | ||||||
| --- a/hostapd/main.c |  | ||||||
| +++ b/hostapd/main.c |  | ||||||
| @@ -1007,6 +1007,7 @@ int main(int argc, char *argv[]) |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
|  	hostapd_global_ctrl_iface_init(&interfaces); |  | ||||||
| +	hostapd_ucode_init(&interfaces); |  | ||||||
|   |  | ||||||
|  	if (hostapd_global_run(&interfaces, daemonize, pid_file)) { |  | ||||||
|  		wpa_printf(MSG_ERROR, "Failed to start eloop"); |  | ||||||
| @@ -1016,6 +1017,7 @@ int main(int argc, char *argv[]) |  | ||||||
|  	ret = 0; |  | ||||||
|   |  | ||||||
|   out: |  | ||||||
| +	hostapd_ucode_free(); |  | ||||||
|  	hostapd_global_ctrl_iface_deinit(&interfaces); |  | ||||||
|  	/* Deinitialize all interfaces */ |  | ||||||
|  	for (i = 0; i < interfaces.count; i++) { |  | ||||||
| --- a/src/ap/hostapd.h |  | ||||||
| +++ b/src/ap/hostapd.h |  | ||||||
| @@ -19,6 +19,7 @@ |  | ||||||
|  #include "ap_config.h" |  | ||||||
|  #include "drivers/driver.h" |  | ||||||
|  #include "ubus.h" |  | ||||||
| +#include "ucode.h" |  | ||||||
|   |  | ||||||
|  #define OCE_STA_CFON_ENABLED(hapd) \ |  | ||||||
|  	((hapd->conf->oce & OCE_STA_CFON) && \ |  | ||||||
| @@ -51,6 +52,10 @@ struct hapd_interfaces { |  | ||||||
|  	struct hostapd_config * (*config_read_cb)(const char *config_fname); |  | ||||||
|  	int (*ctrl_iface_init)(struct hostapd_data *hapd); |  | ||||||
|  	void (*ctrl_iface_deinit)(struct hostapd_data *hapd); |  | ||||||
| +	int (*ctrl_iface_recv)(struct hostapd_data *hapd, |  | ||||||
| +			       char *buf, char *reply, int reply_size, |  | ||||||
| +			       struct sockaddr_storage *from, |  | ||||||
| +			       socklen_t fromlen); |  | ||||||
|  	int (*for_each_interface)(struct hapd_interfaces *interfaces, |  | ||||||
|  				  int (*cb)(struct hostapd_iface *iface, |  | ||||||
|  					    void *ctx), void *ctx); |  | ||||||
| @@ -186,6 +191,7 @@ struct hostapd_data { |  | ||||||
|  	struct hostapd_config *iconf; |  | ||||||
|  	struct hostapd_bss_config *conf; |  | ||||||
|  	struct hostapd_ubus_bss ubus; |  | ||||||
| +	struct hostapd_ucode_bss ucode; |  | ||||||
|  	int interface_added; /* virtual interface added for this BSS */ |  | ||||||
|  	unsigned int started:1; |  | ||||||
|  	unsigned int disabled:1; |  | ||||||
| @@ -506,6 +512,7 @@ struct hostapd_sta_info { |  | ||||||
|   */ |  | ||||||
|  struct hostapd_iface { |  | ||||||
|  	struct hapd_interfaces *interfaces; |  | ||||||
| +	struct hostapd_ucode_iface ucode; |  | ||||||
|  	void *owner; |  | ||||||
|  	char *config_fname; |  | ||||||
|  	struct hostapd_config *conf; |  | ||||||
| @@ -706,6 +713,8 @@ struct hostapd_iface * hostapd_init(stru |  | ||||||
|  struct hostapd_iface * |  | ||||||
|  hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, |  | ||||||
|  			   const char *config_fname, int debug); |  | ||||||
| +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon); |  | ||||||
| +void hostapd_bss_deinit(struct hostapd_data *hapd); |  | ||||||
|  void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
|  			   int reassoc); |  | ||||||
|  void hostapd_interface_deinit_free(struct hostapd_iface *iface); |  | ||||||
| @@ -732,6 +741,7 @@ hostapd_switch_channel_fallback(struct h |  | ||||||
|  void hostapd_cleanup_cs_params(struct hostapd_data *hapd); |  | ||||||
|  void hostapd_periodic_iface(struct hostapd_iface *iface); |  | ||||||
|  int hostapd_owe_trans_get_info(struct hostapd_data *hapd); |  | ||||||
| +void hostapd_owe_update_trans(struct hostapd_iface *iface); |  | ||||||
|  void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx); |  | ||||||
|   |  | ||||||
|  void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap); |  | ||||||
| --- a/src/ap/hostapd.c |  | ||||||
| +++ b/src/ap/hostapd.c |  | ||||||
| @@ -252,6 +252,8 @@ int hostapd_reload_config(struct hostapd |  | ||||||
|  	struct hostapd_config *newconf, *oldconf; |  | ||||||
|  	size_t j; |  | ||||||
|   |  | ||||||
| +	hostapd_ucode_reload_bss(hapd); |  | ||||||
| + |  | ||||||
|  	if (iface->config_fname == NULL) { |  | ||||||
|  		/* Only in-memory config in use - assume it has been updated */ |  | ||||||
|  		hostapd_clear_old(iface); |  | ||||||
| @@ -435,6 +437,7 @@ void hostapd_free_hapd_data(struct hosta |  | ||||||
|  	hapd->beacon_set_done = 0; |  | ||||||
|   |  | ||||||
|  	wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface); |  | ||||||
| +	hostapd_ucode_free_bss(hapd); |  | ||||||
|  	hostapd_ubus_free_bss(hapd); |  | ||||||
|  	accounting_deinit(hapd); |  | ||||||
|  	hostapd_deinit_wpa(hapd); |  | ||||||
| @@ -538,7 +541,7 @@ void hostapd_free_hapd_data(struct hosta |  | ||||||
|   * Most of the modules that are initialized in hostapd_setup_bss() are |  | ||||||
|   * deinitialized here. |  | ||||||
|   */ |  | ||||||
| -static void hostapd_cleanup(struct hostapd_data *hapd) |  | ||||||
| +void hostapd_cleanup(struct hostapd_data *hapd) |  | ||||||
|  { |  | ||||||
|  	wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd, |  | ||||||
|  		   hapd->conf ? hapd->conf->iface : "N/A"); |  | ||||||
| @@ -600,6 +603,7 @@ void hostapd_cleanup_iface_partial(struc |  | ||||||
|  static void hostapd_cleanup_iface(struct hostapd_iface *iface) |  | ||||||
|  { |  | ||||||
|  	wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |  | ||||||
| +	hostapd_ucode_free_iface(iface); |  | ||||||
|  	eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface, |  | ||||||
|  			     NULL); |  | ||||||
|   |  | ||||||
| @@ -1189,6 +1193,7 @@ static int hostapd_start_beacon(struct h |  | ||||||
|  		hapd->driver->set_operstate(hapd->drv_priv, 1); |  | ||||||
|   |  | ||||||
|  	hostapd_ubus_add_bss(hapd); |  | ||||||
| +	hostapd_ucode_add_bss(hapd); |  | ||||||
|   |  | ||||||
|  	return 0; |  | ||||||
|  } |  | ||||||
| @@ -1211,7 +1216,7 @@ static int hostapd_start_beacon(struct h |  | ||||||
|   * initialized. Most of the modules that are initialized here will be |  | ||||||
|   * deinitialized in hostapd_cleanup(). |  | ||||||
|   */ |  | ||||||
| -static int hostapd_setup_bss(struct hostapd_data *hapd, int first, |  | ||||||
| +int hostapd_setup_bss(struct hostapd_data *hapd, int first, |  | ||||||
|  			     bool start_beacon) |  | ||||||
|  { |  | ||||||
|  	struct hostapd_bss_config *conf = hapd->conf; |  | ||||||
| @@ -2237,7 +2242,7 @@ static int hostapd_owe_iface_iter2(struc |  | ||||||
|  #endif /* CONFIG_OWE */ |  | ||||||
|   |  | ||||||
|   |  | ||||||
| -static void hostapd_owe_update_trans(struct hostapd_iface *iface) |  | ||||||
| +void hostapd_owe_update_trans(struct hostapd_iface *iface) |  | ||||||
|  { |  | ||||||
|  #ifdef CONFIG_OWE |  | ||||||
|  	/* Check whether the enabled BSS can complete OWE transition mode |  | ||||||
| @@ -2698,7 +2703,7 @@ hostapd_alloc_bss_data(struct hostapd_if |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| -static void hostapd_bss_deinit(struct hostapd_data *hapd) |  | ||||||
| +void hostapd_bss_deinit(struct hostapd_data *hapd) |  | ||||||
|  { |  | ||||||
|  	if (!hapd) |  | ||||||
|  		return; |  | ||||||
| @@ -3491,7 +3496,8 @@ int hostapd_remove_iface(struct hapd_int |  | ||||||
|  		hapd_iface = interfaces->iface[i]; |  | ||||||
|  		if (hapd_iface == NULL) |  | ||||||
|  			return -1; |  | ||||||
| -		if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) { |  | ||||||
| +		if (!os_strcmp(hapd_iface->phy, buf) || |  | ||||||
| +		    !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) { |  | ||||||
|  			wpa_printf(MSG_INFO, "Remove interface '%s'", buf); |  | ||||||
|  			hapd_iface->driver_ap_teardown = |  | ||||||
|  				!!(hapd_iface->drv_flags & |  | ||||||
| --- a/wpa_supplicant/Makefile |  | ||||||
| +++ b/wpa_supplicant/Makefile |  | ||||||
| @@ -195,8 +195,20 @@ endif |  | ||||||
|  ifdef CONFIG_UBUS |  | ||||||
|  CFLAGS += -DUBUS_SUPPORT |  | ||||||
|  OBJS += ubus.o |  | ||||||
| +LIBS += -lubus |  | ||||||
| +NEED_ULOOP:=y |  | ||||||
| +endif |  | ||||||
| + |  | ||||||
| +ifdef CONFIG_UCODE |  | ||||||
| +CFLAGS += -DUCODE_SUPPORT |  | ||||||
| +OBJS += ../src/utils/ucode.o |  | ||||||
| +OBJS += ucode.o |  | ||||||
| +NEED_ULOOP:=y |  | ||||||
| +endif |  | ||||||
| + |  | ||||||
| +ifdef NEED_ULOOP |  | ||||||
|  OBJS += ../src/utils/uloop.o |  | ||||||
| -LIBS += -lubox -lubus |  | ||||||
| +LIBS += -lubox |  | ||||||
|  endif |  | ||||||
|   |  | ||||||
|  ifdef CONFIG_CODE_COVERAGE |  | ||||||
| @@ -997,6 +1009,9 @@ OBJS += ../src/ap/ctrl_iface_ap.o |  | ||||||
|  ifdef CONFIG_UBUS |  | ||||||
|  OBJS += ../src/ap/ubus.o |  | ||||||
|  endif |  | ||||||
| +ifdef CONFIG_UCODE |  | ||||||
| +OBJS += ../src/ap/ucode.o |  | ||||||
| +endif |  | ||||||
|  endif |  | ||||||
|   |  | ||||||
|  CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY |  | ||||||
| --- a/wpa_supplicant/wpa_supplicant.c |  | ||||||
| +++ b/wpa_supplicant/wpa_supplicant.c |  | ||||||
| @@ -1044,6 +1044,7 @@ void wpa_supplicant_set_state(struct wpa |  | ||||||
|  		sme_sched_obss_scan(wpa_s, 0); |  | ||||||
|  	} |  | ||||||
|  	wpa_s->wpa_state = state; |  | ||||||
| +	wpas_ucode_update_state(wpa_s); |  | ||||||
|   |  | ||||||
|  #ifdef CONFIG_BGSCAN |  | ||||||
|  	if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid) |  | ||||||
| @@ -7594,6 +7595,7 @@ struct wpa_supplicant * wpa_supplicant_a |  | ||||||
|  #endif /* CONFIG_P2P */ |  | ||||||
|   |  | ||||||
|  	wpas_ubus_add_bss(wpa_s); |  | ||||||
| +	wpas_ucode_add_bss(wpa_s); |  | ||||||
|   |  | ||||||
|  	return wpa_s; |  | ||||||
|  } |  | ||||||
| @@ -7621,6 +7623,7 @@ int wpa_supplicant_remove_iface(struct w |  | ||||||
|  	struct wpa_supplicant *parent = wpa_s->parent; |  | ||||||
|  #endif /* CONFIG_MESH */ |  | ||||||
|   |  | ||||||
| +	wpas_ucode_free_bss(wpa_s); |  | ||||||
|  	wpas_ubus_free_bss(wpa_s); |  | ||||||
|   |  | ||||||
|  	/* Remove interface from the global list of interfaces */ |  | ||||||
| @@ -7931,6 +7934,7 @@ struct wpa_global * wpa_supplicant_init( |  | ||||||
|   |  | ||||||
|  	eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, |  | ||||||
|  			       wpas_periodic, global, NULL); |  | ||||||
| +	wpas_ucode_init(global); |  | ||||||
|   |  | ||||||
|  	return global; |  | ||||||
|  } |  | ||||||
| @@ -7969,12 +7973,8 @@ int wpa_supplicant_run(struct wpa_global |  | ||||||
|  	eloop_register_signal_terminate(wpa_supplicant_terminate, global); |  | ||||||
|  	eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); |  | ||||||
|   |  | ||||||
| -	wpas_ubus_add(global); |  | ||||||
| - |  | ||||||
|  	eloop_run(); |  | ||||||
|   |  | ||||||
| -	wpas_ubus_free(global); |  | ||||||
| - |  | ||||||
|  	return 0; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| @@ -8007,6 +8007,8 @@ void wpa_supplicant_deinit(struct wpa_gl |  | ||||||
|   |  | ||||||
|  	wpas_notify_supplicant_deinitialized(global); |  | ||||||
|   |  | ||||||
| +	wpas_ucode_free(); |  | ||||||
| + |  | ||||||
|  	eap_peer_unregister_methods(); |  | ||||||
|  #ifdef CONFIG_AP |  | ||||||
|  	eap_server_unregister_methods(); |  | ||||||
| --- a/wpa_supplicant/wpa_supplicant_i.h |  | ||||||
| +++ b/wpa_supplicant/wpa_supplicant_i.h |  | ||||||
| @@ -22,6 +22,7 @@ |  | ||||||
|  #include "wmm_ac.h" |  | ||||||
|  #include "pasn/pasn_common.h" |  | ||||||
|  #include "ubus.h" |  | ||||||
| +#include "ucode.h" |  | ||||||
|   |  | ||||||
|  extern const char *const wpa_supplicant_version; |  | ||||||
|  extern const char *const wpa_supplicant_license; |  | ||||||
| @@ -689,6 +690,7 @@ struct wpa_supplicant { |  | ||||||
|  	unsigned char perm_addr[ETH_ALEN]; |  | ||||||
|  	char ifname[100]; |  | ||||||
|  	struct wpas_ubus_bss ubus; |  | ||||||
| +	struct wpas_ucode_bss ucode; |  | ||||||
|  #ifdef CONFIG_MATCH_IFACE |  | ||||||
|  	int matched; |  | ||||||
|  #endif /* CONFIG_MATCH_IFACE */ |  | ||||||
| --- a/hostapd/ctrl_iface.c |  | ||||||
| +++ b/hostapd/ctrl_iface.c |  | ||||||
| @@ -4856,6 +4856,7 @@ try_again: |  | ||||||
|  		return -1; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process; |  | ||||||
|  	wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb); |  | ||||||
|   |  | ||||||
|  	return 0; |  | ||||||
| @@ -4957,6 +4958,7 @@ fail: |  | ||||||
|  	os_free(fname); |  | ||||||
|   |  | ||||||
|  	interface->global_ctrl_sock = s; |  | ||||||
| +	interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process; |  | ||||||
|  	eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive, |  | ||||||
|  				 interface, NULL); |  | ||||||
|   |  | ||||||
| --- a/src/drivers/driver.h |  | ||||||
| +++ b/src/drivers/driver.h |  | ||||||
| @@ -3787,6 +3787,25 @@ struct wpa_driver_ops { |  | ||||||
|  			 const char *ifname); |  | ||||||
|   |  | ||||||
|  	/** |  | ||||||
| +	 * if_rename - Rename a virtual interface |  | ||||||
| +	 * @priv: Private driver interface data |  | ||||||
| +	 * @type: Interface type |  | ||||||
| +	 * @ifname: Interface name of the virtual interface to be renamed |  | ||||||
| +	 *	    (NULL when renaming the AP BSS interface) |  | ||||||
| +	 * @new_name: New interface name of the virtual interface |  | ||||||
| +	 * Returns: 0 on success, -1 on failure |  | ||||||
| +	 */ |  | ||||||
| +	int (*if_rename)(void *priv, enum wpa_driver_if_type type, |  | ||||||
| +			 const char *ifname, const char *new_name); |  | ||||||
| + |  | ||||||
| +	/** |  | ||||||
| +	 * set_first_bss - Make a virtual interface the first (primary) bss |  | ||||||
| +	 * @priv: Private driver interface data |  | ||||||
| +	 * Returns: 0 on success, -1 on failure |  | ||||||
| +	 */ |  | ||||||
| +	int (*set_first_bss)(void *priv); |  | ||||||
| + |  | ||||||
| +	/** |  | ||||||
|  	 * set_sta_vlan - Bind a station into a specific interface (AP only) |  | ||||||
|  	 * @priv: Private driver interface data |  | ||||||
|  	 * @ifname: Interface (main or virtual BSS or VLAN) |  | ||||||
| @@ -6440,6 +6459,7 @@ union wpa_event_data { |  | ||||||
|   |  | ||||||
|  	/** |  | ||||||
|  	 * struct ch_switch |  | ||||||
| +	 * @count: Count until channel switch activates |  | ||||||
|  	 * @freq: Frequency of new channel in MHz |  | ||||||
|  	 * @ht_enabled: Whether this is an HT channel |  | ||||||
|  	 * @ch_offset: Secondary channel offset |  | ||||||
| @@ -6450,6 +6470,7 @@ union wpa_event_data { |  | ||||||
|  	 * @punct_bitmap: Puncturing bitmap |  | ||||||
|  	 */ |  | ||||||
|  	struct ch_switch { |  | ||||||
| +		int count; |  | ||||||
|  		int freq; |  | ||||||
|  		int ht_enabled; |  | ||||||
|  		int ch_offset; |  | ||||||
| --- a/src/drivers/driver_nl80211_event.c |  | ||||||
| +++ b/src/drivers/driver_nl80211_event.c |  | ||||||
| @@ -1202,6 +1202,7 @@ static void mlme_event_ch_switch(struct |  | ||||||
|  				 struct nlattr *bw, struct nlattr *cf1, |  | ||||||
|  				 struct nlattr *cf2, |  | ||||||
|  				 struct nlattr *punct_bitmap, |  | ||||||
| +				 struct nlattr *count, |  | ||||||
|  				 int finished) |  | ||||||
|  { |  | ||||||
|  	struct i802_bss *bss; |  | ||||||
| @@ -1265,6 +1266,8 @@ static void mlme_event_ch_switch(struct |  | ||||||
|  		data.ch_switch.cf1 = nla_get_u32(cf1); |  | ||||||
|  	if (cf2) |  | ||||||
|  		data.ch_switch.cf2 = nla_get_u32(cf2); |  | ||||||
| +	if (count) |  | ||||||
| +		data.ch_switch.count = nla_get_u32(count); |  | ||||||
|   |  | ||||||
|  	if (finished) |  | ||||||
|  		bss->flink->freq = data.ch_switch.freq; |  | ||||||
| @@ -3912,6 +3915,7 @@ static void do_process_drv_event(struct |  | ||||||
|  				     tb[NL80211_ATTR_CENTER_FREQ1], |  | ||||||
|  				     tb[NL80211_ATTR_CENTER_FREQ2], |  | ||||||
|  				     tb[NL80211_ATTR_PUNCT_BITMAP], |  | ||||||
| +				     tb[NL80211_ATTR_CH_SWITCH_COUNT], |  | ||||||
|  				     0); |  | ||||||
|  		break; |  | ||||||
|  	case NL80211_CMD_CH_SWITCH_NOTIFY: |  | ||||||
| @@ -3924,6 +3928,7 @@ static void do_process_drv_event(struct |  | ||||||
|  				     tb[NL80211_ATTR_CENTER_FREQ1], |  | ||||||
|  				     tb[NL80211_ATTR_CENTER_FREQ2], |  | ||||||
|  				     tb[NL80211_ATTR_PUNCT_BITMAP], |  | ||||||
| +					 NULL, |  | ||||||
|  				     1); |  | ||||||
|  		break; |  | ||||||
|  	case NL80211_CMD_DISCONNECT: |  | ||||||
| --- a/wpa_supplicant/events.c |  | ||||||
| +++ b/wpa_supplicant/events.c |  | ||||||
| @@ -5389,6 +5389,7 @@ void supplicant_event(void *ctx, enum wp |  | ||||||
|  		event_to_string(event), event); |  | ||||||
|  #endif /* CONFIG_NO_STDOUT_DEBUG */ |  | ||||||
|   |  | ||||||
| +	wpas_ucode_event(wpa_s, event, data); |  | ||||||
|  	switch (event) { |  | ||||||
|  	case EVENT_AUTH: |  | ||||||
|  #ifdef CONFIG_FST |  | ||||||
| --- a/src/ap/ap_drv_ops.h |  | ||||||
| +++ b/src/ap/ap_drv_ops.h |  | ||||||
| @@ -393,6 +393,23 @@ static inline int hostapd_drv_stop_ap(st |  | ||||||
|  	return hapd->driver->stop_ap(hapd->drv_priv); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| +static inline int hostapd_drv_if_rename(struct hostapd_data *hapd, |  | ||||||
| +					enum wpa_driver_if_type type, |  | ||||||
| +					const char *ifname, |  | ||||||
| +					const char *new_name) |  | ||||||
| +{ |  | ||||||
| +	if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv) |  | ||||||
| +		return -1; |  | ||||||
| +	return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| +static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd) |  | ||||||
| +{ |  | ||||||
| +	if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv) |  | ||||||
| +		return 0; |  | ||||||
| +	return hapd->driver->set_first_bss(hapd->drv_priv); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
|  static inline int hostapd_drv_channel_info(struct hostapd_data *hapd, |  | ||||||
|  					   struct wpa_channel_info *ci) |  | ||||||
|  { |  | ||||||
| --- a/src/drivers/driver_nl80211.c |  | ||||||
| +++ b/src/drivers/driver_nl80211.c |  | ||||||
| @@ -1333,7 +1333,7 @@ static void wpa_driver_nl80211_event_rtm |  | ||||||
|  		} |  | ||||||
|  		wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |  | ||||||
|  			   namebuf, ifname); |  | ||||||
| -		if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |  | ||||||
| +		if (drv->first_bss->ifindex != ifi->ifi_index) { |  | ||||||
|  			wpa_printf(MSG_DEBUG, |  | ||||||
|  				   "nl80211: Not the main interface (%s) - do not indicate interface down", |  | ||||||
|  				   drv->first_bss->ifname); |  | ||||||
| @@ -1369,7 +1369,7 @@ static void wpa_driver_nl80211_event_rtm |  | ||||||
|  		} |  | ||||||
|  		wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |  | ||||||
|  			   namebuf, ifname); |  | ||||||
| -		if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |  | ||||||
| +		if (drv->first_bss->ifindex != ifi->ifi_index) { |  | ||||||
|  			wpa_printf(MSG_DEBUG, |  | ||||||
|  				   "nl80211: Not the main interface (%s) - do not indicate interface up", |  | ||||||
|  				   drv->first_bss->ifname); |  | ||||||
| @@ -8432,6 +8432,7 @@ static void *i802_init(struct hostapd_da |  | ||||||
|  	char master_ifname[IFNAMSIZ]; |  | ||||||
|  	int ifindex, br_ifindex = 0; |  | ||||||
|  	int br_added = 0; |  | ||||||
| +	int err; |  | ||||||
|   |  | ||||||
|  	bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |  | ||||||
|  					  params->global_priv, 1, |  | ||||||
| @@ -8491,21 +8492,17 @@ static void *i802_init(struct hostapd_da |  | ||||||
|  	    (params->num_bridge == 0 || !params->bridge[0])) |  | ||||||
|  		add_ifidx(drv, br_ifindex, drv->ifindex); |  | ||||||
|   |  | ||||||
| -	if (bss->added_if_into_bridge || bss->already_in_bridge) { |  | ||||||
| -		int err; |  | ||||||
| - |  | ||||||
| -		drv->rtnl_sk = nl_socket_alloc(); |  | ||||||
| -		if (drv->rtnl_sk == NULL) { |  | ||||||
| -			wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |  | ||||||
| -			goto failed; |  | ||||||
| -		} |  | ||||||
| +	drv->rtnl_sk = nl_socket_alloc(); |  | ||||||
| +	if (drv->rtnl_sk == NULL) { |  | ||||||
| +		wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |  | ||||||
| +		goto failed; |  | ||||||
| +	} |  | ||||||
|   |  | ||||||
| -		err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |  | ||||||
| -		if (err) { |  | ||||||
| -			wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |  | ||||||
| -				   nl_geterror(err)); |  | ||||||
| -			goto failed; |  | ||||||
| -		} |  | ||||||
| +	err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |  | ||||||
| +	if (err) { |  | ||||||
| +		wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |  | ||||||
| +			   nl_geterror(err)); |  | ||||||
| +		goto failed; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
|  	if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |  | ||||||
| @@ -8875,6 +8872,50 @@ static int wpa_driver_nl80211_if_remove( |  | ||||||
|  	return 0; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss, |  | ||||||
| +					enum wpa_driver_if_type type, |  | ||||||
| +					const char *ifname, const char *new_name) |  | ||||||
| +{ |  | ||||||
| +	struct wpa_driver_nl80211_data *drv = bss->drv; |  | ||||||
| +	struct ifinfomsg ifi = { |  | ||||||
| +		.ifi_family = AF_UNSPEC, |  | ||||||
| +		.ifi_index = bss->ifindex, |  | ||||||
| +	}; |  | ||||||
| +	struct nl_msg *msg; |  | ||||||
| +	int res = -ENOMEM; |  | ||||||
| + |  | ||||||
| +	if (ifname) |  | ||||||
| +		ifi.ifi_index = if_nametoindex(ifname); |  | ||||||
| + |  | ||||||
| +	msg = nlmsg_alloc_simple(RTM_SETLINK, 0); |  | ||||||
| +	if (!msg) |  | ||||||
| +		return res; |  | ||||||
| + |  | ||||||
| +	if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0) |  | ||||||
| +		goto out; |  | ||||||
| + |  | ||||||
| +	if (nla_put_string(msg, IFLA_IFNAME, new_name)) |  | ||||||
| +		goto out; |  | ||||||
| + |  | ||||||
| +	res = nl_send_auto_complete(drv->rtnl_sk, msg); |  | ||||||
| +	if (res < 0) |  | ||||||
| +		goto out; |  | ||||||
| + |  | ||||||
| +	res = nl_wait_for_ack(drv->rtnl_sk); |  | ||||||
| +	if (res) { |  | ||||||
| +		wpa_printf(MSG_INFO, |  | ||||||
| +			   "nl80211: Renaming device %s to %s failed: %s", |  | ||||||
| +			   ifname ? ifname : bss->ifname, new_name, nl_geterror(res)); |  | ||||||
| +		goto out; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	if (type == WPA_IF_AP_BSS && !ifname) |  | ||||||
| +		os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname)); |  | ||||||
| + |  | ||||||
| +out: |  | ||||||
| +	nlmsg_free(msg); |  | ||||||
| +	return res; |  | ||||||
| +} |  | ||||||
|   |  | ||||||
|  static int cookie_handler(struct nl_msg *msg, void *arg) |  | ||||||
|  { |  | ||||||
| @@ -10513,6 +10554,37 @@ static int driver_nl80211_if_remove(void |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type, |  | ||||||
| +				    const char *ifname, const char *new_name) |  | ||||||
| +{ |  | ||||||
| +	struct i802_bss *bss = priv; |  | ||||||
| +	return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
| +static int driver_nl80211_set_first_bss(void *priv) |  | ||||||
| +{ |  | ||||||
| +	struct i802_bss *bss = priv, *tbss; |  | ||||||
| +	struct wpa_driver_nl80211_data *drv = bss->drv; |  | ||||||
| + |  | ||||||
| +	if (drv->first_bss == bss) |  | ||||||
| +		return 0; |  | ||||||
| + |  | ||||||
| +	for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |  | ||||||
| +		if (tbss->next != bss) |  | ||||||
| +			continue; |  | ||||||
| + |  | ||||||
| +		tbss->next = bss->next; |  | ||||||
| +		bss->next = drv->first_bss; |  | ||||||
| +		drv->first_bss = bss; |  | ||||||
| +		drv->ctx = bss->ctx; |  | ||||||
| +		return 0; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	return -1; |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
|  static int driver_nl80211_send_mlme(void *priv, const u8 *data, |  | ||||||
|  				    size_t data_len, int noack, |  | ||||||
|  				    unsigned int freq, |  | ||||||
| @@ -13697,6 +13769,8 @@ const struct wpa_driver_ops wpa_driver_n |  | ||||||
|  	.set_acl = wpa_driver_nl80211_set_acl, |  | ||||||
|  	.if_add = wpa_driver_nl80211_if_add, |  | ||||||
|  	.if_remove = driver_nl80211_if_remove, |  | ||||||
| +	.if_rename = driver_nl80211_if_rename, |  | ||||||
| +	.set_first_bss = driver_nl80211_set_first_bss, |  | ||||||
|  	.send_mlme = driver_nl80211_send_mlme, |  | ||||||
|  	.get_hw_feature_data = nl80211_get_hw_feature_data, |  | ||||||
|  	.sta_add = wpa_driver_nl80211_sta_add, |  | ||||||
| --- a/src/ap/ieee802_11.c |  | ||||||
| +++ b/src/ap/ieee802_11.c |  | ||||||
| @@ -547,11 +547,16 @@ static const char * sae_get_password(str |  | ||||||
|  				     struct sae_pt **s_pt, |  | ||||||
|  				     const struct sae_pk **s_pk) |  | ||||||
|  { |  | ||||||
| +	struct hostapd_bss_config *conf = hapd->conf; |  | ||||||
| +	struct hostapd_ssid *ssid = &conf->ssid; |  | ||||||
| +	struct hostapd_sta_wpa_psk_short *psk; |  | ||||||
|  	const char *password = NULL; |  | ||||||
| -	struct sae_password_entry *pw; |  | ||||||
| -	struct sae_pt *pt = NULL; |  | ||||||
| -	const struct sae_pk *pk = NULL; |  | ||||||
| -	struct hostapd_sta_wpa_psk_short *psk = NULL; |  | ||||||
| +	struct sae_password_entry *pw = NULL; |  | ||||||
| + 	struct sae_pt *pt = NULL; |  | ||||||
| + 	const struct sae_pk *pk = NULL; |  | ||||||
| +  |  | ||||||
| +	if (sta && sta->use_sta_psk) |  | ||||||
| +		goto use_sta_psk; |  | ||||||
|   |  | ||||||
|  	for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) { |  | ||||||
|  		if (!is_broadcast_ether_addr(pw->peer_addr) && |  | ||||||
| @@ -582,6 +587,31 @@ static const char * sae_get_password(str |  | ||||||
|  		} |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +use_sta_psk: |  | ||||||
| +	if (!password && sta) { |  | ||||||
| +		for (psk = sta->psk; psk; psk = psk->next) { |  | ||||||
| +			if (!psk->is_passphrase) |  | ||||||
| +				continue; |  | ||||||
| + |  | ||||||
| +			password = psk->passphrase; |  | ||||||
| +			if (!sta->use_sta_psk) |  | ||||||
| +				break; |  | ||||||
| + |  | ||||||
| +			if (sta->sae_pt) { |  | ||||||
| +				pt = sta->sae_pt; |  | ||||||
| +				break; |  | ||||||
| +			} |  | ||||||
| + |  | ||||||
| +			pt = sae_derive_pt(conf->sae_groups, ssid->ssid, |  | ||||||
| +					   ssid->ssid_len, |  | ||||||
| +					   (const u8 *) password, |  | ||||||
| +					   os_strlen(password), |  | ||||||
| +					   NULL); |  | ||||||
| +			sta->sae_pt = pt; |  | ||||||
| +			break; |  | ||||||
| +		} |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
|  	if (pw_entry) |  | ||||||
|  		*pw_entry = pw; |  | ||||||
|  	if (s_pt) |  | ||||||
| @@ -3105,6 +3135,12 @@ static void handle_auth(struct hostapd_d |  | ||||||
|  		goto fail; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	res = hostapd_ucode_sta_auth(hapd, sta); |  | ||||||
| +	if (res) { |  | ||||||
| +		resp = res; |  | ||||||
| +		goto fail; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
|  	sta->flags &= ~WLAN_STA_PREAUTH; |  | ||||||
|  	ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |  | ||||||
|   |  | ||||||
| --- a/src/ap/sta_info.c |  | ||||||
| +++ b/src/ap/sta_info.c |  | ||||||
| @@ -425,6 +425,9 @@ void ap_free_sta(struct hostapd_data *ha |  | ||||||
|  	forced_memzero(sta->last_tk, WPA_TK_MAX_LEN); |  | ||||||
|  #endif /* CONFIG_TESTING_OPTIONS */ |  | ||||||
|   |  | ||||||
| +	if (sta->sae_pt) |  | ||||||
| +		sae_deinit_pt(sta->sae_pt); |  | ||||||
| + |  | ||||||
|  	os_free(sta); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| @@ -1326,6 +1329,8 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  		sta->flags &= ~WLAN_STA_AUTHORIZED; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	if (authorized) |  | ||||||
| +		hostapd_ucode_sta_connected(hapd, sta); |  | ||||||
|  #ifdef CONFIG_P2P |  | ||||||
|  	if (hapd->p2p_group == NULL) { |  | ||||||
|  		if (sta->p2p_ie != NULL && |  | ||||||
| --- a/src/ap/sta_info.h |  | ||||||
| +++ b/src/ap/sta_info.h |  | ||||||
| @@ -198,6 +198,9 @@ struct sta_info { |  | ||||||
|  	int vlan_id_bound; /* updated by ap_sta_bind_vlan() */ |  | ||||||
|  	 /* PSKs from RADIUS authentication server */ |  | ||||||
|  	struct hostapd_sta_wpa_psk_short *psk; |  | ||||||
| +	struct sae_pt *sae_pt; |  | ||||||
| +	int use_sta_psk; |  | ||||||
| +	int psk_idx; |  | ||||||
|   |  | ||||||
|  	char *identity; /* User-Name from RADIUS */ |  | ||||||
|  	char *radius_cui; /* Chargeable-User-Identity from RADIUS */ |  | ||||||
| --- a/src/ap/wpa_auth_glue.c |  | ||||||
| +++ b/src/ap/wpa_auth_glue.c |  | ||||||
| @@ -341,6 +341,7 @@ static const u8 * hostapd_wpa_auth_get_p |  | ||||||
|  	struct sta_info *sta = ap_get_sta(hapd, addr); |  | ||||||
|  	const u8 *psk; |  | ||||||
|   |  | ||||||
| +	sta->psk_idx = 0; |  | ||||||
|  	if (vlan_id) |  | ||||||
|  		*vlan_id = 0; |  | ||||||
|  	if (psk_len) |  | ||||||
| @@ -387,13 +388,18 @@ static const u8 * hostapd_wpa_auth_get_p |  | ||||||
|  	 * returned psk which should not be returned again. |  | ||||||
|  	 * logic list (all hostapd_get_psk; all sta->psk) |  | ||||||
|  	 */ |  | ||||||
| +	if (sta && sta->use_sta_psk) |  | ||||||
| +		psk = NULL; |  | ||||||
|  	if (sta && sta->psk && !psk) { |  | ||||||
|  		struct hostapd_sta_wpa_psk_short *pos; |  | ||||||
| +		int psk_idx; |  | ||||||
|   |  | ||||||
|  		if (vlan_id) |  | ||||||
|  			*vlan_id = 0; |  | ||||||
|  		psk = sta->psk->psk; |  | ||||||
| +		sta->psk_idx = psk_idx = 1; |  | ||||||
|  		for (pos = sta->psk; pos; pos = pos->next) { |  | ||||||
| +			psk_idx++; |  | ||||||
|  			if (pos->is_passphrase) { |  | ||||||
|  				if (pbkdf2_sha1(pos->passphrase, |  | ||||||
|  						hapd->conf->ssid.ssid, |  | ||||||
| @@ -406,10 +412,14 @@ static const u8 * hostapd_wpa_auth_get_p |  | ||||||
|  				pos->is_passphrase = 0; |  | ||||||
|  			} |  | ||||||
|  			if (pos->psk == prev_psk) { |  | ||||||
| +				sta->psk_idx = psk_idx; |  | ||||||
|  				psk = pos->next ? pos->next->psk : NULL; |  | ||||||
|  				break; |  | ||||||
|  			} |  | ||||||
|  		} |  | ||||||
| + |  | ||||||
| +		if (!psk) |  | ||||||
| +			sta->psk_idx = 0; |  | ||||||
|  	} |  | ||||||
|  	return psk; |  | ||||||
|  } |  | ||||||
| @@ -1,539 +0,0 @@ | |||||||
| --- a/src/ap/wpa_auth.h |  | ||||||
| +++ b/src/ap/wpa_auth.h |  | ||||||
| @@ -16,7 +16,11 @@ |  | ||||||
|   |  | ||||||
|  struct vlan_description; |  | ||||||
|  struct mld_info; |  | ||||||
| - |  | ||||||
| +struct rate_description { |  | ||||||
| +	u32 rx; |  | ||||||
| +	u32 tx; |  | ||||||
| +}; |  | ||||||
| +  |  | ||||||
|  #define MAX_OWN_IE_OVERRIDE 256 |  | ||||||
|   |  | ||||||
|  #ifdef _MSC_VER |  | ||||||
| @@ -88,6 +92,7 @@ struct ft_rrb_frame { |  | ||||||
|  #define FT_RRB_IDENTITY      15 |  | ||||||
|  #define FT_RRB_RADIUS_CUI    16 |  | ||||||
|  #define FT_RRB_SESSION_TIMEOUT  17 /* le32 seconds */ |  | ||||||
| +#define FT_RRB_RATE_LIMIT	18 |  | ||||||
|   |  | ||||||
|  struct ft_rrb_tlv { |  | ||||||
|  	le16 type; |  | ||||||
| @@ -368,6 +373,10 @@ struct wpa_auth_callbacks { |  | ||||||
|  			struct vlan_description *vlan); |  | ||||||
|  	int (*get_vlan)(void *ctx, const u8 *sta_addr, |  | ||||||
|  			struct vlan_description *vlan); |  | ||||||
| +	int (*set_rate_limit)(void *ctx, const u8 *sta_addr, |  | ||||||
| +			      struct rate_description *rate); |  | ||||||
| +	int (*get_rate_limit)(void *ctx, const u8 *sta_addr, |  | ||||||
| +			      struct rate_description *rate); |  | ||||||
|  	int (*set_identity)(void *ctx, const u8 *sta_addr, |  | ||||||
|  			    const u8 *identity, size_t identity_len); |  | ||||||
|  	size_t (*get_identity)(void *ctx, const u8 *sta_addr, const u8 **buf); |  | ||||||
| @@ -536,7 +545,7 @@ int wpa_ft_fetch_pmk_r1(struct wpa_authe |  | ||||||
|  			struct vlan_description *vlan, |  | ||||||
|  			const u8 **identity, size_t *identity_len, |  | ||||||
|  			const u8 **radius_cui, size_t *radius_cui_len, |  | ||||||
| -			int *session_timeout); |  | ||||||
| +			int *session_timeout, struct rate_description *rate); |  | ||||||
|   |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|   |  | ||||||
| --- a/src/ap/wpa_auth_glue.c |  | ||||||
| +++ b/src/ap/wpa_auth_glue.c |  | ||||||
| @@ -1200,6 +1200,40 @@ static int hostapd_wpa_auth_get_vlan(voi |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| +static int hostapd_wpa_auth_set_rate_limit(void *ctx, const u8 *sta_addr, |  | ||||||
| +					   struct rate_description *rate) |  | ||||||
| +{ |  | ||||||
| +	struct hostapd_data *hapd = ctx; |  | ||||||
| +	struct sta_info *sta; |  | ||||||
| + |  | ||||||
| +	sta = ap_get_sta(hapd, sta_addr); |  | ||||||
| +	if (!sta || !sta->wpa_sm) |  | ||||||
| +		return -1; |  | ||||||
| + |  | ||||||
| +	memcpy(sta->bandwidth, rate, sizeof(*rate)); |  | ||||||
| +	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |  | ||||||
| +		       HOSTAPD_LEVEL_INFO, "rate-limit %d %d", sta->bandwidth[0], sta->bandwidth[1]); |  | ||||||
| + |  | ||||||
| +	return 0; |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
| +static int hostapd_wpa_auth_get_rate_limit(void *ctx, const u8 *sta_addr, |  | ||||||
| +					   struct rate_description *rate) |  | ||||||
| +{ |  | ||||||
| +	struct hostapd_data *hapd = ctx; |  | ||||||
| +	struct sta_info *sta; |  | ||||||
| + |  | ||||||
| +	sta = ap_get_sta(hapd, sta_addr); |  | ||||||
| +	if (!sta) |  | ||||||
| +		return -1; |  | ||||||
| + |  | ||||||
| +	memcpy(rate, sta->bandwidth, sizeof(*rate)); |  | ||||||
| + |  | ||||||
| +	return 0; |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
|  static int |  | ||||||
|  hostapd_wpa_auth_set_identity(void *ctx, const u8 *sta_addr, |  | ||||||
|  			      const u8 *identity, size_t identity_len) |  | ||||||
| @@ -1640,6 +1674,8 @@ int hostapd_setup_wpa(struct hostapd_dat |  | ||||||
|  		.add_tspec = hostapd_wpa_auth_add_tspec, |  | ||||||
|  		.set_vlan = hostapd_wpa_auth_set_vlan, |  | ||||||
|  		.get_vlan = hostapd_wpa_auth_get_vlan, |  | ||||||
| +		.set_rate_limit = hostapd_wpa_auth_set_rate_limit, |  | ||||||
| +		.get_rate_limit = hostapd_wpa_auth_get_rate_limit, |  | ||||||
|  		.set_identity = hostapd_wpa_auth_set_identity, |  | ||||||
|  		.get_identity = hostapd_wpa_auth_get_identity, |  | ||||||
|  		.set_radius_cui = hostapd_wpa_auth_set_radius_cui, |  | ||||||
| --- a/src/ap/wpa_auth_ft.c |  | ||||||
| +++ b/src/ap/wpa_auth_ft.c |  | ||||||
| @@ -379,6 +379,14 @@ static size_t wpa_ft_vlan_len(const stru |  | ||||||
|  	return tlv_len; |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| +static size_t wpa_ft_rate_limit_len(const struct rate_description *rate) |  | ||||||
| +{ |  | ||||||
| +	if (!rate || (!rate->rx && !rate->tx)) |  | ||||||
| +		return 0; |  | ||||||
| + |  | ||||||
| +	return (sizeof(struct ft_rrb_tlv) + 8); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
|   |  | ||||||
|  static size_t wpa_ft_vlan_lin(const struct vlan_description *vlan, |  | ||||||
|  			      u8 *start, u8 *endpos) |  | ||||||
| @@ -434,10 +442,48 @@ static size_t wpa_ft_vlan_lin(const stru |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| +static size_t wpa_ft_rate_limit_lin(const struct rate_description *rate, |  | ||||||
| +				    u8 *start, u8 *endpos) |  | ||||||
| +{ |  | ||||||
| +	size_t tlv_len; |  | ||||||
| +	int i, len; |  | ||||||
| +	struct ft_rrb_tlv *hdr; |  | ||||||
| +	u8 *pos = start; |  | ||||||
| + |  | ||||||
| +	if (!rate) |  | ||||||
| +		return 0; |  | ||||||
| + |  | ||||||
| +	tlv_len = 0; |  | ||||||
| +	if (rate->rx || rate->tx) { |  | ||||||
| +		tlv_len += sizeof(*hdr); |  | ||||||
| +		if (start + tlv_len > endpos) |  | ||||||
| +			return tlv_len; |  | ||||||
| +		hdr = (struct ft_rrb_tlv *) pos; |  | ||||||
| +		hdr->type = host_to_le16(FT_RRB_RATE_LIMIT); |  | ||||||
| +		hdr->len = host_to_le16(2 * sizeof(le32)); |  | ||||||
| +		pos = start + tlv_len; |  | ||||||
| + |  | ||||||
| +		tlv_len += sizeof(u32); |  | ||||||
| +		if (start + tlv_len > endpos) |  | ||||||
| +			return tlv_len; |  | ||||||
| +		WPA_PUT_LE32(pos, rate->rx); |  | ||||||
| +		pos = start + tlv_len; |  | ||||||
| +		tlv_len += sizeof(u32); |  | ||||||
| +		if (start + tlv_len > endpos) |  | ||||||
| +			return tlv_len; |  | ||||||
| +		WPA_PUT_LE32(pos, rate->tx); |  | ||||||
| +		pos = start + tlv_len; |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
| +	return tlv_len; |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
|  static int wpa_ft_rrb_lin(const struct tlv_list *tlvs1, |  | ||||||
|  			  const struct tlv_list *tlvs2, |  | ||||||
|  			  const struct vlan_description *vlan, |  | ||||||
| -			  u8 **plain, size_t *plain_len) |  | ||||||
| +			  u8 **plain, size_t *plain_len, |  | ||||||
| +			  const struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	u8 *pos, *endpos; |  | ||||||
|  	size_t tlv_len; |  | ||||||
| @@ -445,6 +491,7 @@ static int wpa_ft_rrb_lin(const struct t |  | ||||||
|  	tlv_len = wpa_ft_tlv_len(tlvs1); |  | ||||||
|  	tlv_len += wpa_ft_tlv_len(tlvs2); |  | ||||||
|  	tlv_len += wpa_ft_vlan_len(vlan); |  | ||||||
| +	tlv_len += wpa_ft_rate_limit_len(rate); |  | ||||||
|   |  | ||||||
|  	*plain_len = tlv_len; |  | ||||||
|  	*plain = os_zalloc(tlv_len); |  | ||||||
| @@ -458,6 +505,7 @@ static int wpa_ft_rrb_lin(const struct t |  | ||||||
|  	pos += wpa_ft_tlv_lin(tlvs1, pos, endpos); |  | ||||||
|  	pos += wpa_ft_tlv_lin(tlvs2, pos, endpos); |  | ||||||
|  	pos += wpa_ft_vlan_lin(vlan, pos, endpos); |  | ||||||
| +	pos += wpa_ft_rate_limit_lin(rate, pos, endpos); |  | ||||||
|   |  | ||||||
|  	/* validity check */ |  | ||||||
|  	if (pos != endpos) { |  | ||||||
| @@ -526,7 +574,8 @@ static int wpa_ft_rrb_build(const u8 *ke |  | ||||||
|  			    const struct tlv_list *tlvs_auth, |  | ||||||
|  			    const struct vlan_description *vlan, |  | ||||||
|  			    const u8 *src_addr, u8 type, |  | ||||||
| -			    u8 **packet, size_t *packet_len) |  | ||||||
| +			    u8 **packet, size_t *packet_len, |  | ||||||
| +			    const struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	u8 *plain = NULL, *auth = NULL, *pos, *tmp; |  | ||||||
|  	size_t plain_len = 0, auth_len = 0; |  | ||||||
| @@ -534,10 +583,10 @@ static int wpa_ft_rrb_build(const u8 *ke |  | ||||||
|  	size_t pad_len = 0; |  | ||||||
|   |  | ||||||
|  	*packet = NULL; |  | ||||||
| -	if (wpa_ft_rrb_lin(tlvs_enc0, tlvs_enc1, vlan, &plain, &plain_len) < 0) |  | ||||||
| +	if (wpa_ft_rrb_lin(tlvs_enc0, tlvs_enc1, vlan, &plain, &plain_len, rate) < 0) |  | ||||||
|  		goto out; |  | ||||||
|   |  | ||||||
| -	if (wpa_ft_rrb_lin(tlvs_auth, NULL, NULL, &auth, &auth_len) < 0) |  | ||||||
| +	if (wpa_ft_rrb_lin(tlvs_auth, NULL, NULL, &auth, &auth_len, NULL) < 0) |  | ||||||
|  		goto out; |  | ||||||
|   |  | ||||||
|  	*packet_len = sizeof(u16) + auth_len + plain_len; |  | ||||||
| @@ -700,6 +749,24 @@ static int wpa_ft_get_vlan(struct wpa_au |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| +static int wpa_ft_get_rate_limit(struct wpa_authenticator *wpa_auth, |  | ||||||
| +				 const u8 *sta_addr, struct rate_description *rate) |  | ||||||
| +{ |  | ||||||
| +	if (!wpa_auth->cb->get_rate_limit) |  | ||||||
| +		return -1; |  | ||||||
| +	return wpa_auth->cb->get_rate_limit(wpa_auth->cb_ctx, sta_addr, rate); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
| +static int wpa_ft_set_rate_limit(struct wpa_authenticator *wpa_auth, |  | ||||||
| +				 const u8 *sta_addr, struct rate_description *rate) |  | ||||||
| +{ |  | ||||||
| +	if (!wpa_auth->cb->set_rate_limit) |  | ||||||
| +		return -1; |  | ||||||
| +	return wpa_auth->cb->set_rate_limit(wpa_auth->cb_ctx, sta_addr, rate); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
| + |  | ||||||
|  static int |  | ||||||
|  wpa_ft_set_identity(struct wpa_authenticator *wpa_auth, const u8 *sta_addr, |  | ||||||
|  		    const u8 *identity, size_t identity_len) |  | ||||||
| @@ -1025,7 +1092,7 @@ wpa_ft_rrb_seq_req(struct wpa_authentica |  | ||||||
|   |  | ||||||
|  	if (wpa_ft_rrb_build(key, key_len, NULL, NULL, seq_req_auth, NULL, |  | ||||||
|  			     wpa_auth->addr, FT_PACKET_R0KH_R1KH_SEQ_REQ, |  | ||||||
| -			     &packet, &packet_len) < 0) { |  | ||||||
| +			     &packet, &packet_len, NULL) < 0) { |  | ||||||
|  		item = NULL; /* some other seq resp might still accept this */ |  | ||||||
|  		goto err; |  | ||||||
|  	} |  | ||||||
| @@ -1208,6 +1275,7 @@ struct wpa_ft_pmk_r0_sa { |  | ||||||
|  	u8 spa[ETH_ALEN]; |  | ||||||
|  	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */ |  | ||||||
|  	struct vlan_description *vlan; |  | ||||||
| +	struct rate_description *rate; |  | ||||||
|  	os_time_t expiration; /* 0 for no expiration */ |  | ||||||
|  	u8 *identity; |  | ||||||
|  	size_t identity_len; |  | ||||||
| @@ -1226,6 +1294,7 @@ struct wpa_ft_pmk_r1_sa { |  | ||||||
|  	u8 spa[ETH_ALEN]; |  | ||||||
|  	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */ |  | ||||||
|  	struct vlan_description *vlan; |  | ||||||
| +	struct rate_description *rate; |  | ||||||
|  	u8 *identity; |  | ||||||
|  	size_t identity_len; |  | ||||||
|  	u8 *radius_cui; |  | ||||||
| @@ -1254,6 +1323,7 @@ static void wpa_ft_free_pmk_r0(struct wp |  | ||||||
|   |  | ||||||
|  	os_memset(r0->pmk_r0, 0, PMK_LEN_MAX); |  | ||||||
|  	os_free(r0->vlan); |  | ||||||
| +	os_free(r0->rate); |  | ||||||
|  	os_free(r0->identity); |  | ||||||
|  	os_free(r0->radius_cui); |  | ||||||
|  	os_free(r0); |  | ||||||
| @@ -1307,6 +1377,7 @@ static void wpa_ft_free_pmk_r1(struct wp |  | ||||||
|  	eloop_cancel_timeout(wpa_ft_expire_pmk_r1, r1, NULL); |  | ||||||
|   |  | ||||||
|  	os_memset(r1->pmk_r1, 0, PMK_LEN_MAX); |  | ||||||
| +	os_free(r1->rate); |  | ||||||
|  	os_free(r1->vlan); |  | ||||||
|  	os_free(r1->identity); |  | ||||||
|  	os_free(r1->radius_cui); |  | ||||||
| @@ -1360,7 +1431,8 @@ static int wpa_ft_store_pmk_r0(struct wp |  | ||||||
|  			       const struct vlan_description *vlan, |  | ||||||
|  			       int expires_in, int session_timeout, |  | ||||||
|  			       const u8 *identity, size_t identity_len, |  | ||||||
| -			       const u8 *radius_cui, size_t radius_cui_len) |  | ||||||
| +			       const u8 *radius_cui, size_t radius_cui_len, |  | ||||||
| +			       struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache; |  | ||||||
|  	struct wpa_ft_pmk_r0_sa *r0; |  | ||||||
| @@ -1388,6 +1460,14 @@ static int wpa_ft_store_pmk_r0(struct wp |  | ||||||
|  		} |  | ||||||
|  		*r0->vlan = *vlan; |  | ||||||
|  	} |  | ||||||
| +	if (rate) { |  | ||||||
| +		r0->rate = os_zalloc(sizeof(*rate)); |  | ||||||
| +		if (!r0->rate) { |  | ||||||
| +			bin_clear_free(r0, sizeof(*r0)); |  | ||||||
| +			return -1; |  | ||||||
| +		} |  | ||||||
| +		*r0->rate = *rate; |  | ||||||
| +	} |  | ||||||
|  	if (identity) { |  | ||||||
|  		r0->identity = os_malloc(identity_len); |  | ||||||
|  		if (r0->identity) { |  | ||||||
| @@ -1447,7 +1527,8 @@ static int wpa_ft_store_pmk_r1(struct wp |  | ||||||
|  			       const struct vlan_description *vlan, |  | ||||||
|  			       int expires_in, int session_timeout, |  | ||||||
|  			       const u8 *identity, size_t identity_len, |  | ||||||
| -			       const u8 *radius_cui, size_t radius_cui_len) |  | ||||||
| +			       const u8 *radius_cui, size_t radius_cui_len, |  | ||||||
| +			       struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache; |  | ||||||
|  	int max_expires_in = wpa_auth->conf.r1_max_key_lifetime; |  | ||||||
| @@ -1477,6 +1558,14 @@ static int wpa_ft_store_pmk_r1(struct wp |  | ||||||
|  		} |  | ||||||
|  		*r1->vlan = *vlan; |  | ||||||
|  	} |  | ||||||
| +	if (rate) { |  | ||||||
| +		r1->rate = os_zalloc(sizeof(*rate)); |  | ||||||
| +		if (!r1->rate) { |  | ||||||
| +			bin_clear_free(r1, sizeof(*r1)); |  | ||||||
| +			return -1; |  | ||||||
| +		} |  | ||||||
| +		*r1->rate = *rate; |  | ||||||
| +	} |  | ||||||
|  	if (identity) { |  | ||||||
|  		r1->identity = os_malloc(identity_len); |  | ||||||
|  		if (r1->identity) { |  | ||||||
| @@ -1513,7 +1602,7 @@ int wpa_ft_fetch_pmk_r1(struct wpa_authe |  | ||||||
|  			struct vlan_description *vlan, |  | ||||||
|  			const u8 **identity, size_t *identity_len, |  | ||||||
|  			const u8 **radius_cui, size_t *radius_cui_len, |  | ||||||
| -			int *session_timeout) |  | ||||||
| +			int *session_timeout, struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache; |  | ||||||
|  	struct wpa_ft_pmk_r1_sa *r1; |  | ||||||
| @@ -1533,6 +1622,12 @@ int wpa_ft_fetch_pmk_r1(struct wpa_authe |  | ||||||
|  				*vlan = *r1->vlan; |  | ||||||
|  			if (vlan && !r1->vlan) |  | ||||||
|  				os_memset(vlan, 0, sizeof(*vlan)); |  | ||||||
| +			if (rate) { |  | ||||||
| +				if (r1->rate) |  | ||||||
| +					*rate = *r1->rate; |  | ||||||
| +				else |  | ||||||
| +					memset(rate, 0, sizeof(*rate)); |  | ||||||
| +			} |  | ||||||
|  			if (identity && identity_len) { |  | ||||||
|  				*identity = r1->identity; |  | ||||||
|  				*identity_len = r1->identity_len; |  | ||||||
| @@ -2059,7 +2154,7 @@ static int wpa_ft_pull_pmk_r1(struct wpa |  | ||||||
|   |  | ||||||
|  	if (wpa_ft_rrb_build(key, key_len, req_enc, NULL, req_auth, NULL, |  | ||||||
|  			     sm->wpa_auth->addr, FT_PACKET_R0KH_R1KH_PULL, |  | ||||||
| -			     &packet, &packet_len) < 0) |  | ||||||
| +			     &packet, &packet_len, NULL) < 0) |  | ||||||
|  		return -1; |  | ||||||
|   |  | ||||||
|  	ft_pending_req_ies = wpabuf_alloc_copy(ies, ies_len); |  | ||||||
| @@ -2088,6 +2183,7 @@ int wpa_ft_store_pmk_fils(struct wpa_sta |  | ||||||
|  { |  | ||||||
|  	int expires_in = sm->wpa_auth->conf.r0_key_lifetime; |  | ||||||
|  	struct vlan_description vlan; |  | ||||||
| +	struct rate_description rate; |  | ||||||
|  	const u8 *identity, *radius_cui; |  | ||||||
|  	size_t identity_len, radius_cui_len; |  | ||||||
|  	int session_timeout; |  | ||||||
| @@ -2099,6 +2195,7 @@ int wpa_ft_store_pmk_fils(struct wpa_sta |  | ||||||
|  			   MAC2STR(sm->addr)); |  | ||||||
|  		return -1; |  | ||||||
|  	} |  | ||||||
| +	wpa_ft_get_rate_limit(sm->wpa_auth, sm->addr, &rate); |  | ||||||
|   |  | ||||||
|  	identity_len = wpa_ft_get_identity(sm->wpa_auth, sm->addr, &identity); |  | ||||||
|  	radius_cui_len = wpa_ft_get_radius_cui(sm->wpa_auth, sm->addr, |  | ||||||
| @@ -2108,7 +2205,7 @@ int wpa_ft_store_pmk_fils(struct wpa_sta |  | ||||||
|  	return wpa_ft_store_pmk_r0(sm->wpa_auth, sm->addr, pmk_r0, pmk_r0_len, |  | ||||||
|  				   pmk_r0_name, sm->pairwise, &vlan, expires_in, |  | ||||||
|  				   session_timeout, identity, identity_len, |  | ||||||
| -				   radius_cui, radius_cui_len); |  | ||||||
| +				   radius_cui, radius_cui_len, &rate); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| @@ -2172,6 +2269,7 @@ void wpa_auth_ft_store_keys(struct wpa_s |  | ||||||
|  	int psk_local = sm->wpa_auth->conf.ft_psk_generate_local; |  | ||||||
|  	int expires_in = sm->wpa_auth->conf.r0_key_lifetime; |  | ||||||
|  	struct vlan_description vlan; |  | ||||||
| +	struct rate_description rate; |  | ||||||
|  	const u8 *identity, *radius_cui; |  | ||||||
|  	size_t identity_len, radius_cui_len; |  | ||||||
|  	int session_timeout; |  | ||||||
| @@ -2185,6 +2283,8 @@ void wpa_auth_ft_store_keys(struct wpa_s |  | ||||||
|  		return; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	wpa_ft_get_rate_limit(sm->wpa_auth, sm->addr, &rate); |  | ||||||
| + |  | ||||||
|  	identity_len = wpa_ft_get_identity(sm->wpa_auth, sm->addr, &identity); |  | ||||||
|  	radius_cui_len = wpa_ft_get_radius_cui(sm->wpa_auth, sm->addr, |  | ||||||
|  					       &radius_cui); |  | ||||||
| @@ -2195,11 +2295,12 @@ void wpa_auth_ft_store_keys(struct wpa_s |  | ||||||
|  			    pmk_r0_name, |  | ||||||
|  			    sm->pairwise, &vlan, expires_in, |  | ||||||
|  			    session_timeout, identity, identity_len, |  | ||||||
| -			    radius_cui, radius_cui_len); |  | ||||||
| +			    radius_cui, radius_cui_len, &rate); |  | ||||||
|  	wpa_ft_store_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1, key_len, |  | ||||||
|  			    sm->pmk_r1_name, sm->pairwise, &vlan, |  | ||||||
|  			    expires_in, session_timeout, identity, |  | ||||||
| -			    identity_len, radius_cui, radius_cui_len); |  | ||||||
| +			    identity_len, radius_cui, radius_cui_len, |  | ||||||
| +			    &rate); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| @@ -3100,7 +3201,8 @@ static int wpa_ft_local_derive_pmk_r1(st |  | ||||||
|  				      const u8 **radius_cui, |  | ||||||
|  				      size_t *radius_cui_len, |  | ||||||
|  				      int *out_session_timeout, |  | ||||||
| -				      size_t *pmk_r1_len) |  | ||||||
| +				      size_t *pmk_r1_len, |  | ||||||
| +				      struct rate_description *rate) |  | ||||||
|  { |  | ||||||
|  	struct wpa_auth_config *conf = &wpa_auth->conf; |  | ||||||
|  	const struct wpa_ft_pmk_r0_sa *r0; |  | ||||||
| @@ -3136,7 +3238,8 @@ static int wpa_ft_local_derive_pmk_r1(st |  | ||||||
|  			    out_pmk_r1_name, |  | ||||||
|  			    sm->pairwise, r0->vlan, expires_in, session_timeout, |  | ||||||
|  			    r0->identity, r0->identity_len, |  | ||||||
| -			    r0->radius_cui, r0->radius_cui_len); |  | ||||||
| +			    r0->radius_cui, r0->radius_cui_len, |  | ||||||
| +			    r0->rate); |  | ||||||
|   |  | ||||||
|  	*out_pairwise = sm->pairwise; |  | ||||||
|  	if (vlan) { |  | ||||||
| @@ -3146,6 +3249,13 @@ static int wpa_ft_local_derive_pmk_r1(st |  | ||||||
|  			os_memset(vlan, 0, sizeof(*vlan)); |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	if (rate) { |  | ||||||
| +		if (r0->rate) |  | ||||||
| +			*rate = *r0->rate; |  | ||||||
| +		else |  | ||||||
| +			os_memset(rate, 0, sizeof(*rate)); |  | ||||||
| +	} |  | ||||||
| + |  | ||||||
|  	if (identity && identity_len) { |  | ||||||
|  		*identity = r0->identity; |  | ||||||
|  		*identity_len = r0->identity_len; |  | ||||||
| @@ -3178,6 +3288,7 @@ static int wpa_ft_process_auth_req(struc |  | ||||||
|  	u8 *pos, *end; |  | ||||||
|  	int pairwise, session_timeout = 0; |  | ||||||
|  	struct vlan_description vlan; |  | ||||||
| +	struct rate_description rate = {}; |  | ||||||
|  	const u8 *identity, *radius_cui; |  | ||||||
|  	size_t identity_len = 0, radius_cui_len = 0; |  | ||||||
|  	size_t pmk_r1_len, kdk_len, len; |  | ||||||
| @@ -3274,7 +3385,7 @@ static int wpa_ft_process_auth_req(struc |  | ||||||
|  					pmk_r1, &pmk_r1_len, &pairwise, &vlan, |  | ||||||
|  					&identity, &identity_len, &radius_cui, |  | ||||||
|  					&radius_cui_len, |  | ||||||
| -					&session_timeout) == 0) { |  | ||||||
| +					&session_timeout, &rate) == 0) { |  | ||||||
|  			wpa_printf(MSG_DEBUG, |  | ||||||
|  				   "FT: Found PMKR1Name (using SHA%zu) from local cache", |  | ||||||
|  				   pmk_r1_len * 8); |  | ||||||
| @@ -3290,7 +3401,7 @@ static int wpa_ft_process_auth_req(struc |  | ||||||
|  				       pmk_r1_name, pmk_r1, &pairwise, |  | ||||||
|  				       &vlan, &identity, &identity_len, |  | ||||||
|  				       &radius_cui, &radius_cui_len, |  | ||||||
| -				       &session_timeout, &pmk_r1_len) == 0) { |  | ||||||
| +				       &session_timeout, &pmk_r1_len, &rate) == 0) { |  | ||||||
|  		wpa_printf(MSG_DEBUG, |  | ||||||
|  			   "FT: Generated PMK-R1 based on local PMK-R0"); |  | ||||||
|  		goto pmk_r1_derived; |  | ||||||
| @@ -3392,6 +3503,7 @@ pmk_r1_derived: |  | ||||||
|  		wpa_printf(MSG_DEBUG, "FT: Failed to configure VLAN"); |  | ||||||
|  		goto out; |  | ||||||
|  	} |  | ||||||
| +	wpa_ft_set_rate_limit(sm->wpa_auth, sm->addr, &rate); |  | ||||||
|  	if (wpa_ft_set_identity(sm->wpa_auth, sm->addr, |  | ||||||
|  				identity, identity_len) < 0 || |  | ||||||
|  	    wpa_ft_set_radius_cui(sm->wpa_auth, sm->addr, |  | ||||||
| @@ -3973,7 +4085,7 @@ static int wpa_ft_rrb_build_r0(const u8 |  | ||||||
|   |  | ||||||
|  	ret = wpa_ft_rrb_build(key, key_len, tlvs, sess_tlv, tlv_auth, |  | ||||||
|  			       pmk_r0->vlan, src_addr, type, |  | ||||||
| -			       packet, packet_len); |  | ||||||
| +			       packet, packet_len, pmk_r0->rate); |  | ||||||
|   |  | ||||||
|  	forced_memzero(pmk_r1, sizeof(pmk_r1)); |  | ||||||
|   |  | ||||||
| @@ -4113,7 +4225,7 @@ static int wpa_ft_rrb_rx_pull(struct wpa |  | ||||||
|  		ret = wpa_ft_rrb_build(key, key_len, resp, NULL, resp_auth, |  | ||||||
|  				       NULL, wpa_auth->addr, |  | ||||||
|  				       FT_PACKET_R0KH_R1KH_RESP, |  | ||||||
| -				       &packet, &packet_len); |  | ||||||
| +				       &packet, &packet_len, NULL); |  | ||||||
|  	} else { |  | ||||||
|  		ret = wpa_ft_rrb_build_r0(key, key_len, resp, r0, f_r1kh_id, |  | ||||||
|  					  f_s1kh_id, resp_auth, wpa_auth->addr, |  | ||||||
| @@ -4165,11 +4277,15 @@ static int wpa_ft_rrb_rx_r1(struct wpa_a |  | ||||||
|  	size_t f_expires_in_len; |  | ||||||
|  	size_t f_identity_len, f_radius_cui_len; |  | ||||||
|  	size_t f_session_timeout_len; |  | ||||||
| +	size_t f_rate_len; |  | ||||||
| +	const u8 *f_rate; |  | ||||||
|  	int pairwise; |  | ||||||
|  	int ret = -1; |  | ||||||
|  	int expires_in; |  | ||||||
|  	int session_timeout; |  | ||||||
|  	struct vlan_description vlan; |  | ||||||
| +	struct rate_description rate; |  | ||||||
| +	int has_rate = 0; |  | ||||||
|  	size_t pmk_r1_len; |  | ||||||
|   |  | ||||||
|  	RRB_GET_AUTH(FT_RRB_R0KH_ID, r0kh_id, msgtype, -1); |  | ||||||
| @@ -4279,6 +4395,13 @@ static int wpa_ft_rrb_rx_r1(struct wpa_a |  | ||||||
|  	wpa_printf(MSG_DEBUG, "FT: vlan %d%s", |  | ||||||
|  		   le_to_host16(vlan.untagged), vlan.tagged[0] ? "+" : ""); |  | ||||||
|   |  | ||||||
| +	RRB_GET_OPTIONAL(FT_RRB_RATE_LIMIT, rate, msgtype, 2 * sizeof(le32)); |  | ||||||
| +	if (f_rate) { |  | ||||||
| +		memcpy(&rate, f_rate, sizeof(rate)); |  | ||||||
| +		rate.rx = le_to_host32(rate.rx); |  | ||||||
| +		rate.tx = le_to_host32(rate.tx); |  | ||||||
| +		has_rate = 1; |  | ||||||
| +	}; |  | ||||||
|  	RRB_GET_OPTIONAL(FT_RRB_IDENTITY, identity, msgtype, -1); |  | ||||||
|  	if (f_identity) |  | ||||||
|  		wpa_hexdump_ascii(MSG_DEBUG, "FT: Identity", f_identity, |  | ||||||
| @@ -4301,7 +4424,7 @@ static int wpa_ft_rrb_rx_r1(struct wpa_a |  | ||||||
|  				f_pmk_r1_name, |  | ||||||
|  				pairwise, &vlan, expires_in, session_timeout, |  | ||||||
|  				f_identity, f_identity_len, f_radius_cui, |  | ||||||
| -				f_radius_cui_len) < 0) |  | ||||||
| +				f_radius_cui_len, has_rate ? &rate : 0) < 0) |  | ||||||
|  		goto out; |  | ||||||
|   |  | ||||||
|  	ret = 0; |  | ||||||
| @@ -4614,7 +4737,7 @@ static int wpa_ft_rrb_rx_seq_req(struct |  | ||||||
|   |  | ||||||
|  	if (wpa_ft_rrb_build(key, key_len, NULL, NULL, seq_resp_auth, NULL, |  | ||||||
|  			     wpa_auth->addr, FT_PACKET_R0KH_R1KH_SEQ_RESP, |  | ||||||
| -			     &packet, &packet_len) < 0) |  | ||||||
| +			     &packet, &packet_len, NULL) < 0) |  | ||||||
|  		goto out; |  | ||||||
|   |  | ||||||
|  	wpa_ft_rrb_oui_send(wpa_auth, src_addr, |  | ||||||
| @@ -1,10 +0,0 @@ | |||||||
| --- a/src/ap/wpa_auth_i.h |  | ||||||
| +++ b/src/ap/wpa_auth_i.h |  | ||||||
| @@ -54,6 +54,7 @@ struct wpa_state_machine { |  | ||||||
|  	bool MICVerified; |  | ||||||
|  	bool GUpdateStationKeys; |  | ||||||
|  	u8 ANonce[WPA_NONCE_LEN]; |  | ||||||
| +	struct os_reltime ANonce_time; |  | ||||||
|  	u8 SNonce[WPA_NONCE_LEN]; |  | ||||||
|  	u8 alt_SNonce[WPA_NONCE_LEN]; |  | ||||||
|  	u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN]; |  | ||||||
| @@ -1,147 +0,0 @@ | |||||||
| --- a/src/ap/ieee802_11.c |  | ||||||
| +++ b/src/ap/ieee802_11.c |  | ||||||
| @@ -522,6 +522,7 @@ static void handle_auth_ft_finish(void * |  | ||||||
|   |  | ||||||
|  	hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |  | ||||||
|  		       HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |  | ||||||
| +	hostapd_ubus_notify(hapd, "ft-finish", sta->addr); |  | ||||||
|  	sta->flags |= WLAN_STA_AUTH; |  | ||||||
|  	mlme_authenticate_indication(hapd, sta); |  | ||||||
|  } |  | ||||||
| @@ -5273,6 +5274,8 @@ static void handle_assoc(struct hostapd_ |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
|  	sta = ap_get_sta(hapd, mgmt->sa); |  | ||||||
| +	if (sta && reassoc) |  | ||||||
| +		memcpy(sta->origin_ap, mgmt->u.reassoc_req.current_ap, 6); |  | ||||||
|  #ifdef CONFIG_IEEE80211R_AP |  | ||||||
|  	if (sta && sta->auth_alg == WLAN_AUTH_FT && |  | ||||||
|  	    (sta->flags & WLAN_STA_AUTH) == 0) { |  | ||||||
| @@ -5426,6 +5429,7 @@ static void handle_assoc(struct hostapd_ |  | ||||||
|  		.type = HOSTAPD_UBUS_ASSOC_REQ, |  | ||||||
|  		.mgmt_frame = mgmt, |  | ||||||
|  		.ssi_signal = rssi, |  | ||||||
| +		.reassoc = reassoc, |  | ||||||
|  	}; |  | ||||||
|   |  | ||||||
|  	/* followed by SSID and Supported rates; and HT capabilities if 802.11n |  | ||||||
| @@ -6496,7 +6500,7 @@ static void handle_assoc_cb(struct hosta |  | ||||||
|  		 * Open, static WEP, FT protocol, or FILS; no separate |  | ||||||
|  		 * authorization step. |  | ||||||
|  		 */ |  | ||||||
| -		ap_sta_set_authorized(hapd, sta, 1); |  | ||||||
| +		_ap_sta_set_authorized(hapd, sta, 1, reassoc); |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
|  	if (reassoc) |  | ||||||
| --- a/src/ap/ubus.c |  | ||||||
| +++ b/src/ap/ubus.c |  | ||||||
| @@ -1870,6 +1870,8 @@ int hostapd_ubus_handle_event(struct hos |  | ||||||
|  	if (req->ssi_signal) |  | ||||||
|  		blobmsg_add_u32(&b, "signal", req->ssi_signal); |  | ||||||
|  	blobmsg_add_u32(&b, "freq", hapd->iface->freq); |  | ||||||
| +	if (req->reassoc && req->mgmt_frame) |  | ||||||
| +		blobmsg_add_macaddr(&b, "origin", req->mgmt_frame->u.reassoc_req.current_ap); |  | ||||||
|   |  | ||||||
|  	if (req->elems) { |  | ||||||
|  		if(req->elems->ht_capabilities) |  | ||||||
| @@ -1940,6 +1942,7 @@ void hostapd_ubus_notify(struct hostapd_ |  | ||||||
|  	blob_buf_init(&b, 0); |  | ||||||
|  	blobmsg_add_macaddr(&b, "address", addr); |  | ||||||
|  	blobmsg_add_string(&b, "ifname", hapd->conf->iface); |  | ||||||
| +	blobmsg_printf(&b, "target", MACSTR, MAC2STR(hapd->conf->bssid)); |  | ||||||
|   |  | ||||||
|  	ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); |  | ||||||
|  } |  | ||||||
| @@ -1958,7 +1961,7 @@ void hostapd_ubus_notify_csa(struct host |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| -void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta) |  | ||||||
| +void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta, int reassoc) |  | ||||||
|  { |  | ||||||
|  	if (!hapd->ubus.obj.has_subscribers) |  | ||||||
|  		return; |  | ||||||
| @@ -1975,6 +1978,9 @@ void hostapd_ubus_notify_authorized(stru |  | ||||||
|  		blobmsg_add_u32(&b, "", sta->bandwidth[1]); |  | ||||||
|  		blobmsg_close_array(&b, r); |  | ||||||
|  	} |  | ||||||
| +	if (reassoc) |  | ||||||
| +		blobmsg_add_macaddr(&b, "origin", sta->origin_ap); |  | ||||||
| +	blobmsg_printf(&b, "target", MACSTR, MAC2STR(hapd->conf->bssid)); |  | ||||||
|   |  | ||||||
|  	ubus_notify(ctx, &hapd->ubus.obj, "sta-authorized", b.head, -1); |  | ||||||
|  } |  | ||||||
| --- a/src/ap/ubus.h |  | ||||||
| +++ b/src/ap/ubus.h |  | ||||||
| @@ -22,6 +22,7 @@ struct hostapd_ubus_request { |  | ||||||
|  	const struct ieee802_11_elems *elems; |  | ||||||
|  	int ssi_signal; /* dBm */ |  | ||||||
|  	const u8 *addr; |  | ||||||
| +	int reassoc; |  | ||||||
|  }; |  | ||||||
|   |  | ||||||
|  struct hostapd_iface; |  | ||||||
| @@ -49,7 +50,7 @@ void hostapd_ubus_remove_vlan(struct hos |  | ||||||
|   |  | ||||||
|  int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req); |  | ||||||
|  void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac); |  | ||||||
| -void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta); |  | ||||||
| +void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta, int reassoc); |  | ||||||
|  void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, |  | ||||||
|  				       const u8 *addr, u8 token, u8 rep_mode, |  | ||||||
|  				       struct rrm_measurement_beacon_report *rep, |  | ||||||
| --- a/src/ap/sta_info.c |  | ||||||
| +++ b/src/ap/sta_info.c |  | ||||||
| @@ -1297,8 +1297,8 @@ const u8 * ap_sta_wpa_get_dpp_pkhash(str |  | ||||||
|  } |  | ||||||
|   |  | ||||||
|   |  | ||||||
| -void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
| -			   int authorized) |  | ||||||
| +void _ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
| +			    int authorized, int reassoc) |  | ||||||
|  { |  | ||||||
|  	const u8 *dev_addr = NULL; |  | ||||||
|  	char buf[100]; |  | ||||||
| @@ -1404,7 +1404,7 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  					 dpp_pkhash, SHA256_MAC_LEN); |  | ||||||
|  		} |  | ||||||
|   |  | ||||||
| -		hostapd_ubus_notify_authorized(hapd, sta); |  | ||||||
| +		hostapd_ubus_notify_authorized(hapd, sta, reassoc); |  | ||||||
|  		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s%s", |  | ||||||
|  			buf, ip_addr, keyid_buf, dpp_pkhash_buf, alg_buf); |  | ||||||
|   |  | ||||||
| @@ -1434,6 +1434,11 @@ void ap_sta_set_authorized(struct hostap |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_FST */ |  | ||||||
|  } |  | ||||||
| +void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
| +			   int authorized) |  | ||||||
| +{ |  | ||||||
| +	_ap_sta_set_authorized(hapd, sta, authorized, 0); |  | ||||||
| +} |  | ||||||
|   |  | ||||||
|   |  | ||||||
|  void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
| --- a/src/ap/sta_info.h |  | ||||||
| +++ b/src/ap/sta_info.h |  | ||||||
| @@ -102,6 +102,7 @@ struct sta_info { |  | ||||||
|  	struct sta_info *next; /* next entry in sta list */ |  | ||||||
|  	struct sta_info *hnext; /* next entry in hash table list */ |  | ||||||
|  	u8 addr[6]; |  | ||||||
| +	u8 origin_ap[6]; |  | ||||||
|  	be32 ipaddr; |  | ||||||
|  	struct dl_list ip6addr; /* list head for struct ip6addr */ |  | ||||||
|  	u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */ |  | ||||||
| @@ -398,6 +399,9 @@ const u8 * ap_sta_wpa_get_dpp_pkhash(str |  | ||||||
|  void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |  | ||||||
|  		       const u8 *addr, u16 reason); |  | ||||||
|   |  | ||||||
| +void _ap_sta_set_authorized(struct hostapd_data *hapd, |  | ||||||
| +			    struct sta_info *sta, int authorized, |  | ||||||
| +			    int reassoc); |  | ||||||
|  void ap_sta_set_authorized(struct hostapd_data *hapd, |  | ||||||
|  			   struct sta_info *sta, int authorized); |  | ||||||
|  static inline int ap_sta_is_authorized(struct sta_info *sta) |  | ||||||
| @@ -1,86 +0,0 @@ | |||||||
| --- a/hostapd/config_file.c |  | ||||||
| +++ b/hostapd/config_file.c |  | ||||||
| @@ -3152,6 +3152,8 @@ static int hostapd_config_fill(struct ho |  | ||||||
|  		bss->ft_over_ds = atoi(pos); |  | ||||||
|  	} else if (os_strcmp(buf, "ft_psk_generate_local") == 0) { |  | ||||||
|  		bss->ft_psk_generate_local = atoi(pos); |  | ||||||
| +	} else if (os_strcmp(buf, "ft_l2_refresh") == 0) { |  | ||||||
| +		bss->ft_l2_refresh = atoi(pos); |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|  #ifndef CONFIG_NO_CTRL_IFACE |  | ||||||
|  	} else if (os_strcmp(buf, "ctrl_interface") == 0) { |  | ||||||
| --- a/src/ap/ap_config.h |  | ||||||
| +++ b/src/ap/ap_config.h |  | ||||||
| @@ -401,6 +401,7 @@ struct hostapd_bss_config { |  | ||||||
|  	int pmk_r1_push; |  | ||||||
|  	int ft_over_ds; |  | ||||||
|  	int ft_psk_generate_local; |  | ||||||
| +	int ft_l2_refresh; |  | ||||||
|  	int r1_max_key_lifetime; |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|   |  | ||||||
| --- a/src/ap/wpa_auth_glue.c |  | ||||||
| +++ b/src/ap/wpa_auth_glue.c |  | ||||||
| @@ -1495,6 +1495,28 @@ static void hostapd_request_radius_psk(v |  | ||||||
|  #endif /* CONFIG_NO_RADIUS */ |  | ||||||
|   |  | ||||||
|   |  | ||||||
| +static void wpa_ft_refresh(void *eloop_data, void *user_data) |  | ||||||
| +{ |  | ||||||
| +	struct hostapd_data *hapd = eloop_data; |  | ||||||
| +	struct ft_rrb_frame *frame; |  | ||||||
| +	struct l2_ethhdr *buf; |  | ||||||
| +	size_t len; |  | ||||||
| + |  | ||||||
| +	len = sizeof(*buf) + sizeof(*frame); |  | ||||||
| +	buf = os_zalloc(len); |  | ||||||
| +	frame = (struct ft_rrb_frame *)(buf + 1); |  | ||||||
| +	frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB; |  | ||||||
| +	frame->packet_type = FT_PACKET_REQUEST; |  | ||||||
| +	memset(buf->h_dest, 0xff, ETH_ALEN); |  | ||||||
| +	os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN); |  | ||||||
| +	buf->h_proto = host_to_be16(ETH_P_RRB); |  | ||||||
| +	l2_packet_send(hapd->l2, buf->h_dest, ETH_P_RRB, (u8 *) buf, len); |  | ||||||
| +	os_free(buf); |  | ||||||
| + |  | ||||||
| +	eloop_register_timeout(hapd->conf->ft_l2_refresh, 0, wpa_ft_refresh, |  | ||||||
| +			       hapd, NULL); |  | ||||||
| +} |  | ||||||
| + |  | ||||||
|  int hostapd_setup_wpa(struct hostapd_data *hapd) |  | ||||||
|  { |  | ||||||
|  	struct wpa_auth_config _conf; |  | ||||||
| @@ -1640,6 +1662,9 @@ int hostapd_setup_wpa(struct hostapd_dat |  | ||||||
|  				   "Failed to open ETH_P_OUI interface"); |  | ||||||
|  			return -1; |  | ||||||
|  		} |  | ||||||
| + |  | ||||||
| +		if (hapd->conf->ft_l2_refresh) |  | ||||||
| +			wpa_ft_refresh(hapd, NULL); |  | ||||||
|  	} |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|   |  | ||||||
| @@ -1655,7 +1680,6 @@ void hostapd_reconfig_wpa(struct hostapd |  | ||||||
|  	wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf); |  | ||||||
|  } |  | ||||||
|   |  | ||||||
| - |  | ||||||
|  void hostapd_deinit_wpa(struct hostapd_data *hapd) |  | ||||||
|  { |  | ||||||
|  	ieee80211_tkip_countermeasures_deinit(hapd); |  | ||||||
| @@ -1679,6 +1703,7 @@ void hostapd_deinit_wpa(struct hostapd_d |  | ||||||
|  				   "information element from interface %s", |  | ||||||
|  				   hapd->conf->iface); |  | ||||||
|  		} |  | ||||||
| + |  | ||||||
|  	} |  | ||||||
|  	ieee802_1x_deinit(hapd); |  | ||||||
|   |  | ||||||
| @@ -1687,6 +1712,7 @@ void hostapd_deinit_wpa(struct hostapd_d |  | ||||||
|  	hostapd_wpa_ft_rrb_rx_later(hapd, NULL); /* flush without delivering */ |  | ||||||
|  	eloop_cancel_timeout(hostapd_oui_deliver_later, hapd, ELOOP_ALL_CTX); |  | ||||||
|  	hostapd_oui_deliver_later(hapd, NULL); /* flush without delivering */ |  | ||||||
| +	eloop_cancel_timeout(wpa_ft_refresh, hapd, ELOOP_ALL_CTX); |  | ||||||
|  	l2_packet_deinit(hapd->l2); |  | ||||||
|  	hapd->l2 = NULL; |  | ||||||
|  	hostapd_wpa_unregister_ft_oui(hapd); |  | ||||||
| @@ -1,27 +0,0 @@ | |||||||
| --- a/src/ap/hostapd.c |  | ||||||
| +++ b/src/ap/hostapd.c |  | ||||||
| @@ -1995,6 +1995,13 @@ static int hostapd_owe_iface_iter(struct |  | ||||||
|  		    is_zero_ether_addr(bss->own_addr)) |  | ||||||
|  			continue; |  | ||||||
|   |  | ||||||
| +		if (!os_memcmp(hapd->conf->owe_transition_bssid, bss->own_addr, |  | ||||||
| +			       ETH_ALEN) && |  | ||||||
| +		    hapd->conf->owe_transition_ssid_len == bss->conf->ssid.ssid_len && |  | ||||||
| +		    !os_memcmp(hapd->conf->owe_transition_ssid, bss->conf->ssid.ssid, |  | ||||||
| +			       bss->conf->ssid.ssid_len)) |  | ||||||
| +			return 0; |  | ||||||
| + |  | ||||||
|  		os_memcpy(hapd->conf->owe_transition_bssid, bss->own_addr, |  | ||||||
|  			  ETH_ALEN); |  | ||||||
|  		os_memcpy(hapd->conf->owe_transition_ssid, |  | ||||||
| @@ -2011,10 +2018,6 @@ static int hostapd_owe_iface_iter(struct |  | ||||||
|   |  | ||||||
|  int hostapd_owe_trans_get_info(struct hostapd_data *hapd) |  | ||||||
|  { |  | ||||||
| -	if (hapd->conf->owe_transition_ssid_len > 0 && |  | ||||||
| -	    !is_zero_ether_addr(hapd->conf->owe_transition_bssid)) |  | ||||||
| -		return 0; |  | ||||||
| - |  | ||||||
|  	/* Find transition mode SSID/BSSID information from a BSS operated by |  | ||||||
|  	 * this hostapd instance. */ |  | ||||||
|  	if (!hapd->iface->interfaces || |  | ||||||
| @@ -1,53 +0,0 @@ | |||||||
| From 98b6503b87bb36bf2f5ae16e52e230e8870c867f Mon Sep 17 00:00:00 2001 |  | ||||||
| From: Venkat Chimata <venkata@shasta.cloud> |  | ||||||
| Date: Fri, 28 Jun 2024 14:39:31 +0530 |  | ||||||
| Subject: [PATCH] hostapd: Fix DVLAN + 802.1x issue |  | ||||||
|  |  | ||||||
| In case of swconfig switches, the basename of the interface should be based on the last dot. |  | ||||||
| Earlier it was done based on the first dot, which would result in incorrect basename. |  | ||||||
| For example if the interface name is eth0.4087 then the vlan->ifname would be eth0.4087.  (A dot at the end) . |  | ||||||
| Before this patch, the basename was returned as eth0. It should be eth0.4087 |  | ||||||
|  |  | ||||||
| Also fixed the return code by adding a default value of 0 and removed an unncessary check |  | ||||||
| for if_add before ubus add call. |  | ||||||
|  |  | ||||||
| Signed-off-by: Venkat Chimata <venkata@shasta.cloud> |  | ||||||
| --- |  | ||||||
|  src/ap/vlan_init.c | 7 ++++--- |  | ||||||
|  1 file changed, 4 insertions(+), 3 deletions(-) |  | ||||||
|  |  | ||||||
| diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c |  | ||||||
| index 3e27671..cfeb1e5 100644 |  | ||||||
| --- a/src/ap/vlan_init.c |  | ||||||
| +++ b/src/ap/vlan_init.c |  | ||||||
| @@ -23,7 +23,8 @@ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, |  | ||||||
|  		       int existsok) |  | ||||||
|  { |  | ||||||
|  	bool vlan_exists = iface_exists(vlan->ifname); |  | ||||||
| -	int ret; |  | ||||||
| +	int ret = 0; |  | ||||||
| + |  | ||||||
|  #ifdef CONFIG_WEP |  | ||||||
|  	int i; |  | ||||||
|   |  | ||||||
| @@ -38,7 +39,7 @@ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, |  | ||||||
|  #endif /* CONFIG_WEP */ |  | ||||||
|   |  | ||||||
|  	if (!hapd->driver || !hapd->driver->if_add) { |  | ||||||
| -		char *dot = strstr(vlan->ifname, "."); |  | ||||||
| +		char *dot = strrchr(vlan->ifname, '.'); |  | ||||||
|  		if (dot) |  | ||||||
|  			*dot = '\0'; |  | ||||||
|  		ret = 0; |  | ||||||
| @@ -59,7 +60,7 @@ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, |  | ||||||
|  	if (hapd->wpa_auth) |  | ||||||
|  		ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id); |  | ||||||
|   |  | ||||||
| -	if (!ret && !vlan_exists && hapd->driver->if_add) |  | ||||||
| +	if (!ret && !vlan_exists) |  | ||||||
|  		hostapd_ubus_add_vlan(hapd, vlan); |  | ||||||
|   |  | ||||||
|  	if (ret == 0) |  | ||||||
| --  |  | ||||||
| 2.34.1 |  | ||||||
|  |  | ||||||
| @@ -1,14 +0,0 @@ | |||||||
| --- a/src/ap/beacon.c |  | ||||||
| +++ b/src/ap/beacon.c |  | ||||||
| @@ -934,8 +934,10 @@ void handle_probe_req(struct hostapd_dat |  | ||||||
|  	int ubus_response; |  | ||||||
|   |  | ||||||
|  	if (hapd->iconf->rssi_ignore_probe_request && ssi_signal && |  | ||||||
| -	    ssi_signal < hapd->iconf->rssi_ignore_probe_request) |  | ||||||
| +	    ssi_signal < hapd->iconf->rssi_ignore_probe_request) { |  | ||||||
| +		hostapd_ubus_notify_rssi(hapd, "rssi-ignore-probe", mgmt->sa, ssi_signal); |  | ||||||
|  		return; |  | ||||||
| +	} |  | ||||||
|   |  | ||||||
|  	if (len < IEEE80211_HDRLEN) |  | ||||||
|  		return; |  | ||||||
| @@ -1,11 +0,0 @@ | |||||||
| --- a/src/radius/radius.c |  | ||||||
| +++ b/src/radius/radius.c |  | ||||||
| @@ -755,7 +755,7 @@ struct radius_attr_hdr * radius_msg_add_ |  | ||||||
|  			ext->length = sizeof(*ext) + 1 + alen; |  | ||||||
|  			ext->ext_type = ext_type; |  | ||||||
|  			wpabuf_put_u8(msg->buf, data_len > alen ? 0x80 : 0); |  | ||||||
| -			wpabuf_put_data(msg->buf, data, data_len); |  | ||||||
| +			wpabuf_put_data(msg->buf, data, alen); |  | ||||||
|  			data += alen; |  | ||||||
|  			data_len -= alen; |  | ||||||
|  			if (radius_msg_add_attr_to_array( |  | ||||||
| @@ -1,69 +0,0 @@ | |||||||
| --- a/hostapd/config_file.c |  | ||||||
| +++ b/hostapd/config_file.c |  | ||||||
| @@ -3154,6 +3154,8 @@ static int hostapd_config_fill(struct ho |  | ||||||
|  		bss->ft_psk_generate_local = atoi(pos); |  | ||||||
|  	} else if (os_strcmp(buf, "ft_l2_refresh") == 0) { |  | ||||||
|  		bss->ft_l2_refresh = atoi(pos); |  | ||||||
| +	} else if (os_strcmp(buf, "ft_key") == 0) { |  | ||||||
| +		strncpy(bss->ft_key, pos, sizeof(bss->ft_key)); |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|  #ifndef CONFIG_NO_CTRL_IFACE |  | ||||||
|  	} else if (os_strcmp(buf, "ctrl_interface") == 0) { |  | ||||||
| @@ -4996,8 +4998,22 @@ struct hostapd_config * hostapd_config_r |  | ||||||
|   |  | ||||||
|  	fclose(f); |  | ||||||
|   |  | ||||||
| -	for (i = 0; i < conf->num_bss; i++) |  | ||||||
| +	for (i = 0; i < conf->num_bss; i++) { |  | ||||||
| +		if (*conf->bss[i]->ft_key) { |  | ||||||
| +			u8 buffer[128]; |  | ||||||
| +			sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X %02X%02X%02X%02X%02X%02X %s", MAC2STR(conf->bss[i]->bssid), MAC2STR(conf->bss[i]->bssid), conf->bss[i]->ft_key); |  | ||||||
| +			add_r0kh(conf->bss[i], buffer); |  | ||||||
| +			sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X %02X:%02X:%02X:%02X:%02X:%02X %s", MAC2STR(conf->bss[i]->bssid), MAC2STR(conf->bss[i]->bssid), conf->bss[i]->ft_key); |  | ||||||
| +			add_r1kh(conf->bss[i], buffer); |  | ||||||
| +			sprintf(buffer, "ff:ff:ff:ff:ff:ff * %s", conf->bss[i]->ft_key); |  | ||||||
| +			add_r0kh(conf->bss[i], buffer); |  | ||||||
| +			sprintf(buffer, "00:00:00:00:00:00 00:00:00:00:00:00 %s", conf->bss[i]->ft_key); |  | ||||||
| +			add_r1kh(conf->bss[i], buffer); |  | ||||||
| +			hexstr2bin(conf->bss[i]->bssid, conf->bss[i]->r1_key_holder, FT_R1KH_ID_LEN);  |  | ||||||
| +			conf->bss[i]->r0_key_holder_bssid = 1; |  | ||||||
| +		} |  | ||||||
|  		hostapd_set_security_params(conf->bss[i], 1); |  | ||||||
| +	} |  | ||||||
|   |  | ||||||
|  	if (hostapd_config_check(conf, 1)) |  | ||||||
|  		errors++; |  | ||||||
| --- a/src/ap/ap_config.h |  | ||||||
| +++ b/src/ap/ap_config.h |  | ||||||
| @@ -403,6 +403,7 @@ struct hostapd_bss_config { |  | ||||||
|  	int ft_psk_generate_local; |  | ||||||
|  	int ft_l2_refresh; |  | ||||||
|  	int r1_max_key_lifetime; |  | ||||||
| +	u8 ft_key[65]; |  | ||||||
|  #endif /* CONFIG_IEEE80211R_AP */ |  | ||||||
|   |  | ||||||
|  	char *ctrl_interface; /* directory for UNIX domain sockets */ |  | ||||||
| --- a/src/ap/ap_config.h |  | ||||||
| +++ b/src/ap/ap_config.h |  | ||||||
| @@ -390,6 +390,7 @@ struct hostapd_bss_config { |  | ||||||
|  	/* IEEE 802.11r - Fast BSS Transition */ |  | ||||||
|  	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN]; |  | ||||||
|  	u8 r1_key_holder[FT_R1KH_ID_LEN]; |  | ||||||
| +	int r0_key_holder_bssid; |  | ||||||
|  	u32 r0_key_lifetime; /* PMK-R0 lifetime seconds */ |  | ||||||
|  	int rkh_pos_timeout; |  | ||||||
|  	int rkh_neg_timeout; |  | ||||||
| --- a/src/ap/wpa_auth_glue.c |  | ||||||
| +++ b/src/ap/wpa_auth_glue.c |  | ||||||
| @@ -80,7 +80,10 @@ static void hostapd_wpa_auth_conf(struct |  | ||||||
|  	os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len); |  | ||||||
|  	os_memcpy(wconf->mobility_domain, conf->mobility_domain, |  | ||||||
|  		  MOBILITY_DOMAIN_ID_LEN); |  | ||||||
| -	if (conf->nas_identifier && |  | ||||||
| +	if (1 || conf->r0_key_holder_bssid) { |  | ||||||
| +		sprintf(wconf->r0_key_holder, "%02X%02X%02X%02X%02X%02X", MAC2STR(conf->bssid)); |  | ||||||
| +		wconf->r0_key_holder_len = 12; |  | ||||||
| +	} else if (conf->nas_identifier && |  | ||||||
|  	    os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) { |  | ||||||
|  		wconf->r0_key_holder_len = os_strlen(conf->nas_identifier); |  | ||||||
|  		os_memcpy(wconf->r0_key_holder, conf->nas_identifier, |  | ||||||
| @@ -1,46 +0,0 @@ | |||||||
| Index: hostapd-2023-09-08-e5ccbfc6/src/ap/wpa_auth_ft.c |  | ||||||
| =================================================================== |  | ||||||
| --- hostapd-2023-09-08-e5ccbfc6.orig/src/ap/wpa_auth_ft.c |  | ||||||
| +++ hostapd-2023-09-08-e5ccbfc6/src/ap/wpa_auth_ft.c |  | ||||||
| @@ -3293,6 +3297,8 @@ static int wpa_ft_process_auth_req(struc |  | ||||||
|  	size_t identity_len = 0, radius_cui_len = 0; |  | ||||||
|  	size_t pmk_r1_len, kdk_len, len; |  | ||||||
|  	int retval = WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
| +	struct os_reltime now; |  | ||||||
| +	struct rsn_ftie *ftie; |  | ||||||
|   |  | ||||||
|  	*resp_ies = NULL; |  | ||||||
|  	*resp_ies_len = 0; |  | ||||||
| @@ -3324,6 +3330,9 @@ static int wpa_ft_process_auth_req(struc |  | ||||||
|  		goto out; |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
| +	ftie = (struct rsn_ftie *) parse.ftie; |  | ||||||
| +	os_memcpy(sm->SNonce, ftie->snonce, WPA_NONCE_LEN); |  | ||||||
| + |  | ||||||
|  	if (parse.r0kh_id == NULL) { |  | ||||||
|  		wpa_printf(MSG_DEBUG, "FT: Invalid FTIE - no R0KH-ID"); |  | ||||||
|  		retval = WLAN_STATUS_INVALID_FTIE; |  | ||||||
| @@ -3424,10 +3433,18 @@ pmk_r1_derived: |  | ||||||
|  	os_memcpy(sm->pmk_r1, pmk_r1, pmk_r1_len); |  | ||||||
|  	sm->pmk_r1_len = pmk_r1_len; |  | ||||||
|   |  | ||||||
| -	if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { |  | ||||||
| -		wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " |  | ||||||
| -			   "ANonce"); |  | ||||||
| -		goto out; |  | ||||||
| +	if (os_get_reltime(&now) < 0 || |  | ||||||
| +	    os_reltime_expired(&now, &sm->ANonce_time, 1)) { |  | ||||||
| +		if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { |  | ||||||
| +			wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " |  | ||||||
| +				   "ANonce"); |  | ||||||
| +			return WLAN_STATUS_UNSPECIFIED_FAILURE; |  | ||||||
| +		} |  | ||||||
| +		sm->ANonce_time.sec = now.sec; |  | ||||||
| +		sm->ANonce_time.usec = now.usec; |  | ||||||
| +		wpa_printf(MSG_INFO, "FT: ANonce was randomized"); |  | ||||||
| +	} else { |  | ||||||
| +		wpa_printf(MSG_INFO, "FT: ANonce has not expired"); |  | ||||||
|  	} |  | ||||||
|   |  | ||||||
|  	/* Now that we know the correct PMK-R1 length and as such, the length |  | ||||||
| @@ -1,719 +0,0 @@ | |||||||
| #include "utils/includes.h" |  | ||||||
| #include "utils/common.h" |  | ||||||
| #include "utils/eloop.h" |  | ||||||
| #include "crypto/crypto.h" |  | ||||||
| #include "crypto/tls.h" |  | ||||||
|  |  | ||||||
| #include "ap/ap_config.h" |  | ||||||
| #include "eap_server/eap.h" |  | ||||||
| #include "radius/radius.h" |  | ||||||
| #include "radius/radius_server.h" |  | ||||||
| #include "eap_register.h" |  | ||||||
|  |  | ||||||
| #include <libubox/blobmsg_json.h> |  | ||||||
| #include <libubox/blobmsg.h> |  | ||||||
| #include <libubox/avl.h> |  | ||||||
| #include <libubox/avl-cmp.h> |  | ||||||
| #include <libubox/kvlist.h> |  | ||||||
|  |  | ||||||
| #include <sys/stat.h> |  | ||||||
| #include <fnmatch.h> |  | ||||||
|  |  | ||||||
| #define VENDOR_ID_WISPR 14122 |  | ||||||
| #define VENDOR_ATTR_SIZE 6 |  | ||||||
|  |  | ||||||
| struct radius_parse_attr_data { |  | ||||||
| 	unsigned int vendor; |  | ||||||
| 	u8 type; |  | ||||||
| 	int size; |  | ||||||
| 	char format; |  | ||||||
| 	const char *data; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct radius_parse_attr_state { |  | ||||||
| 	struct hostapd_radius_attr *prev; |  | ||||||
| 	struct hostapd_radius_attr *attr; |  | ||||||
| 	struct wpabuf *buf; |  | ||||||
| 	void *attrdata; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct radius_user_state { |  | ||||||
| 	struct avl_node node; |  | ||||||
| 	struct eap_user data; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct radius_user_data { |  | ||||||
| 	struct kvlist users; |  | ||||||
| 	struct avl_tree user_state; |  | ||||||
| 	struct blob_attr *wildcard; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct radius_state { |  | ||||||
| 	struct radius_server_data *radius; |  | ||||||
| 	struct eap_config eap; |  | ||||||
|  |  | ||||||
| 	struct radius_user_data phase1, phase2; |  | ||||||
| 	const char *user_file; |  | ||||||
| 	time_t user_file_ts; |  | ||||||
|  |  | ||||||
| 	int n_attrs; |  | ||||||
| 	struct hostapd_radius_attr *attrs; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct radius_config { |  | ||||||
| 	struct tls_connection_params tls; |  | ||||||
| 	struct radius_server_conf radius; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| enum { |  | ||||||
| 	USER_ATTR_PASSWORD, |  | ||||||
| 	USER_ATTR_HASH, |  | ||||||
| 	USER_ATTR_SALT, |  | ||||||
| 	USER_ATTR_METHODS, |  | ||||||
| 	USER_ATTR_RADIUS, |  | ||||||
| 	USER_ATTR_VLAN, |  | ||||||
| 	USER_ATTR_MAX_RATE_UP, |  | ||||||
| 	USER_ATTR_MAX_RATE_DOWN, |  | ||||||
| 	__USER_ATTR_MAX |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| static void radius_tls_event(void *ctx, enum tls_event ev, |  | ||||||
| 			      union tls_event_data *data) |  | ||||||
| { |  | ||||||
| 	switch (ev) { |  | ||||||
| 	case TLS_CERT_CHAIN_SUCCESS: |  | ||||||
| 		wpa_printf(MSG_DEBUG, "radius: remote certificate verification success"); |  | ||||||
| 		break; |  | ||||||
| 	case TLS_CERT_CHAIN_FAILURE: |  | ||||||
| 		wpa_printf(MSG_INFO, "radius: certificate chain failure: reason=%d depth=%d subject='%s' err='%s'", |  | ||||||
| 			   data->cert_fail.reason, |  | ||||||
| 			   data->cert_fail.depth, |  | ||||||
| 			   data->cert_fail.subject, |  | ||||||
| 			   data->cert_fail.reason_txt); |  | ||||||
| 		break; |  | ||||||
| 	case TLS_PEER_CERTIFICATE: |  | ||||||
| 		wpa_printf(MSG_DEBUG, "radius: peer certificate: depth=%d serial_num=%s subject=%s", |  | ||||||
| 			   data->peer_cert.depth, |  | ||||||
| 			   data->peer_cert.serial_num ? data->peer_cert.serial_num : "N/A", |  | ||||||
| 			   data->peer_cert.subject); |  | ||||||
| 		break; |  | ||||||
| 	case TLS_ALERT: |  | ||||||
| 		if (data->alert.is_local) |  | ||||||
| 			wpa_printf(MSG_DEBUG, "radius: local TLS alert: %s", |  | ||||||
| 				   data->alert.description); |  | ||||||
| 		else |  | ||||||
| 			wpa_printf(MSG_DEBUG, "radius: remote TLS alert: %s", |  | ||||||
| 				   data->alert.description); |  | ||||||
| 		break; |  | ||||||
| 	case TLS_UNSAFE_RENEGOTIATION_DISABLED: |  | ||||||
| 		/* Not applicable to TLS server */ |  | ||||||
| 		break; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void radius_userdata_init(struct radius_user_data *u) |  | ||||||
| { |  | ||||||
| 	kvlist_init(&u->users, kvlist_blob_len); |  | ||||||
| 	avl_init(&u->user_state, avl_strcmp, false, NULL); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void radius_userdata_free(struct radius_user_data *u) |  | ||||||
| { |  | ||||||
| 	struct radius_user_state *s, *tmp; |  | ||||||
|  |  | ||||||
| 	kvlist_free(&u->users); |  | ||||||
| 	free(u->wildcard); |  | ||||||
| 	u->wildcard = NULL; |  | ||||||
| 	avl_remove_all_elements(&u->user_state, s, node, tmp) |  | ||||||
| 		free(s); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| radius_userdata_load(struct radius_user_data *u, struct blob_attr *data) |  | ||||||
| { |  | ||||||
| 	enum { |  | ||||||
| 		USERSTATE_USERS, |  | ||||||
| 		USERSTATE_WILDCARD, |  | ||||||
| 		__USERSTATE_MAX, |  | ||||||
| 	}; |  | ||||||
| 	static const struct blobmsg_policy policy[__USERSTATE_MAX] = { |  | ||||||
| 		[USERSTATE_USERS] = { "users", BLOBMSG_TYPE_TABLE }, |  | ||||||
| 		[USERSTATE_WILDCARD] = { "wildcard", BLOBMSG_TYPE_ARRAY }, |  | ||||||
| 	}; |  | ||||||
| 	struct blob_attr *tb[__USERSTATE_MAX], *cur; |  | ||||||
| 	int rem; |  | ||||||
|  |  | ||||||
| 	if (!data) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	blobmsg_parse(policy, __USERSTATE_MAX, tb, blobmsg_data(data), blobmsg_len(data)); |  | ||||||
|  |  | ||||||
| 	blobmsg_for_each_attr(cur, tb[USERSTATE_USERS], rem) |  | ||||||
| 		kvlist_set(&u->users, blobmsg_name(cur), cur); |  | ||||||
|  |  | ||||||
| 	if (tb[USERSTATE_WILDCARD]) |  | ||||||
| 		u->wildcard = blob_memdup(tb[USERSTATE_WILDCARD]); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| load_userfile(struct radius_state *s) |  | ||||||
| { |  | ||||||
| 	enum { |  | ||||||
| 		USERDATA_PHASE1, |  | ||||||
| 		USERDATA_PHASE2, |  | ||||||
| 		__USERDATA_MAX |  | ||||||
| 	}; |  | ||||||
| 	static const struct blobmsg_policy policy[__USERDATA_MAX] = { |  | ||||||
| 		[USERDATA_PHASE1] = { "phase1", BLOBMSG_TYPE_TABLE }, |  | ||||||
| 		[USERDATA_PHASE2] = { "phase2", BLOBMSG_TYPE_TABLE }, |  | ||||||
| 	}; |  | ||||||
| 	struct blob_attr *tb[__USERDATA_MAX], *cur; |  | ||||||
| 	static struct blob_buf b; |  | ||||||
| 	struct stat st; |  | ||||||
| 	int rem; |  | ||||||
|  |  | ||||||
| 	if (stat(s->user_file, &st)) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	if (s->user_file_ts == st.st_mtime) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	s->user_file_ts = st.st_mtime; |  | ||||||
| 	radius_userdata_free(&s->phase1); |  | ||||||
| 	radius_userdata_free(&s->phase2); |  | ||||||
|  |  | ||||||
| 	blob_buf_init(&b, 0); |  | ||||||
| 	blobmsg_add_json_from_file(&b, s->user_file); |  | ||||||
| 	blobmsg_parse(policy, __USERDATA_MAX, tb, blob_data(b.head), blob_len(b.head)); |  | ||||||
| 	radius_userdata_load(&s->phase1, tb[USERDATA_PHASE1]); |  | ||||||
| 	radius_userdata_load(&s->phase2, tb[USERDATA_PHASE2]); |  | ||||||
|  |  | ||||||
| 	blob_buf_free(&b); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static struct blob_attr * |  | ||||||
| radius_user_get(struct radius_user_data *s, const char *name) |  | ||||||
| { |  | ||||||
| 	struct blob_attr *cur; |  | ||||||
| 	int rem; |  | ||||||
|  |  | ||||||
| 	cur = kvlist_get(&s->users, name); |  | ||||||
| 	if (cur) |  | ||||||
| 		return cur; |  | ||||||
|  |  | ||||||
| 	blobmsg_for_each_attr(cur, s->wildcard, rem) { |  | ||||||
| 		static const struct blobmsg_policy policy = { |  | ||||||
| 			"name", BLOBMSG_TYPE_STRING |  | ||||||
| 		}; |  | ||||||
| 		struct blob_attr *pattern; |  | ||||||
|  |  | ||||||
| 		if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		blobmsg_parse(&policy, 1, &pattern, blobmsg_data(cur), blobmsg_len(cur)); |  | ||||||
| 		if (!name) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		if (!fnmatch(blobmsg_get_string(pattern), name, 0)) |  | ||||||
| 			return cur; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static struct radius_parse_attr_data * |  | ||||||
| radius_parse_attr(struct blob_attr *attr) |  | ||||||
| { |  | ||||||
| 	static const struct blobmsg_policy policy[4] = { |  | ||||||
| 		{ .type = BLOBMSG_TYPE_INT32 }, |  | ||||||
| 		{ .type = BLOBMSG_TYPE_INT32 }, |  | ||||||
| 		{ .type = BLOBMSG_TYPE_STRING }, |  | ||||||
| 		{ .type = BLOBMSG_TYPE_STRING }, |  | ||||||
| 	}; |  | ||||||
| 	static struct radius_parse_attr_data data; |  | ||||||
| 	struct blob_attr *tb[4]; |  | ||||||
| 	const char *format; |  | ||||||
|  |  | ||||||
| 	blobmsg_parse_array(policy, ARRAY_SIZE(policy), tb, blobmsg_data(attr), blobmsg_len(attr)); |  | ||||||
|  |  | ||||||
| 	if (!tb[0] || !tb[1] || !tb[2] || !tb[3]) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	format = blobmsg_get_string(tb[2]); |  | ||||||
| 	if (strlen(format) != 1) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	data.vendor = blobmsg_get_u32(tb[0]); |  | ||||||
| 	data.type = blobmsg_get_u32(tb[1]); |  | ||||||
| 	data.format = format[0]; |  | ||||||
| 	data.data = blobmsg_get_string(tb[3]); |  | ||||||
| 	data.size = strlen(data.data); |  | ||||||
|  |  | ||||||
| 	switch (data.format) { |  | ||||||
| 	case 's': |  | ||||||
| 		break; |  | ||||||
| 	case 'x': |  | ||||||
| 		if (data.size & 1) |  | ||||||
| 			return NULL; |  | ||||||
| 		data.size /= 2; |  | ||||||
| 		break; |  | ||||||
| 	case 'd': |  | ||||||
| 		data.size = 4; |  | ||||||
| 		break; |  | ||||||
| 	default: |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return &data; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| radius_count_attrs(struct blob_attr **tb, int *n_attr, size_t *attr_size) |  | ||||||
| { |  | ||||||
| 	struct blob_attr *data = tb[USER_ATTR_RADIUS]; |  | ||||||
| 	struct blob_attr *cur; |  | ||||||
| 	int rem; |  | ||||||
|  |  | ||||||
| 	blobmsg_for_each_attr(cur, data, rem) { |  | ||||||
| 		struct radius_parse_attr_data *data; |  | ||||||
| 		size_t prev = *attr_size; |  | ||||||
|  |  | ||||||
| 		data = radius_parse_attr(cur); |  | ||||||
| 		if (!data) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		*attr_size += data->size; |  | ||||||
| 		if (data->vendor) |  | ||||||
| 			*attr_size += VENDOR_ATTR_SIZE; |  | ||||||
|  |  | ||||||
| 		(*n_attr)++; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	*n_attr += !!tb[USER_ATTR_VLAN] * 3 + |  | ||||||
| 		   !!tb[USER_ATTR_MAX_RATE_UP] + |  | ||||||
| 		   !!tb[USER_ATTR_MAX_RATE_DOWN]; |  | ||||||
| 	*attr_size += !!tb[USER_ATTR_VLAN] * (4 + 4 + 5) + |  | ||||||
| 		      !!tb[USER_ATTR_MAX_RATE_UP] * (4 + VENDOR_ATTR_SIZE) + |  | ||||||
| 		      !!tb[USER_ATTR_MAX_RATE_DOWN] * (4 + VENDOR_ATTR_SIZE); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void * |  | ||||||
| radius_add_attr(struct radius_parse_attr_state *state, |  | ||||||
| 		u32 vendor, u8 type, u8 len) |  | ||||||
| { |  | ||||||
| 	struct hostapd_radius_attr *attr; |  | ||||||
| 	struct wpabuf *buf; |  | ||||||
| 	void *val; |  | ||||||
|  |  | ||||||
| 	val = state->attrdata; |  | ||||||
|  |  | ||||||
| 	buf = state->buf++; |  | ||||||
| 	buf->buf = val; |  | ||||||
|  |  | ||||||
| 	attr = state->attr++; |  | ||||||
| 	attr->val = buf; |  | ||||||
| 	attr->type = type; |  | ||||||
|  |  | ||||||
| 	if (state->prev) |  | ||||||
| 		state->prev->next = attr; |  | ||||||
| 	state->prev = attr; |  | ||||||
|  |  | ||||||
| 	if (vendor) { |  | ||||||
| 		u8 *vendor_hdr = val + 4; |  | ||||||
|  |  | ||||||
| 		WPA_PUT_BE32(val, vendor); |  | ||||||
| 		vendor_hdr[0] = type; |  | ||||||
| 		vendor_hdr[1] = len + 2; |  | ||||||
|  |  | ||||||
| 		len += VENDOR_ATTR_SIZE; |  | ||||||
| 		val += VENDOR_ATTR_SIZE; |  | ||||||
| 		attr->type = RADIUS_ATTR_VENDOR_SPECIFIC; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	buf->size = buf->used = len; |  | ||||||
| 	state->attrdata += len; |  | ||||||
|  |  | ||||||
| 	return val; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| radius_parse_attrs(struct blob_attr **tb, struct radius_parse_attr_state *state) |  | ||||||
| { |  | ||||||
| 	struct blob_attr *data = tb[USER_ATTR_RADIUS]; |  | ||||||
| 	struct hostapd_radius_attr *prev = NULL; |  | ||||||
| 	struct blob_attr *cur; |  | ||||||
| 	int len, rem; |  | ||||||
| 	void *val; |  | ||||||
|  |  | ||||||
| 	if ((cur = tb[USER_ATTR_VLAN]) != NULL && blobmsg_get_u32(cur) < 4096) { |  | ||||||
| 		char buf[5]; |  | ||||||
|  |  | ||||||
| 		val = radius_add_attr(state, 0, RADIUS_ATTR_TUNNEL_TYPE, 4); |  | ||||||
| 		WPA_PUT_BE32(val, RADIUS_TUNNEL_TYPE_VLAN); |  | ||||||
|  |  | ||||||
| 		val = radius_add_attr(state, 0, RADIUS_ATTR_TUNNEL_MEDIUM_TYPE, 4); |  | ||||||
| 		WPA_PUT_BE32(val, RADIUS_TUNNEL_MEDIUM_TYPE_802); |  | ||||||
|  |  | ||||||
| 		len = snprintf(buf, sizeof(buf), "%d", blobmsg_get_u32(cur)); |  | ||||||
| 		val = radius_add_attr(state, 0, RADIUS_ATTR_TUNNEL_PRIVATE_GROUP_ID, len); |  | ||||||
| 		memcpy(val, buf, len); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if ((cur = tb[USER_ATTR_MAX_RATE_UP]) != NULL) { |  | ||||||
| 		val = radius_add_attr(state, VENDOR_ID_WISPR, 7, 4); |  | ||||||
| 		WPA_PUT_BE32(val, blobmsg_get_u32(cur)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if ((cur = tb[USER_ATTR_MAX_RATE_DOWN]) != NULL) { |  | ||||||
| 		val = radius_add_attr(state, VENDOR_ID_WISPR, 8, 4); |  | ||||||
| 		WPA_PUT_BE32(val, blobmsg_get_u32(cur)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	blobmsg_for_each_attr(cur, data, rem) { |  | ||||||
| 		struct radius_parse_attr_data *data; |  | ||||||
| 		void *val; |  | ||||||
| 		int size; |  | ||||||
|  |  | ||||||
| 		data = radius_parse_attr(cur); |  | ||||||
| 		if (!data) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		val = radius_add_attr(state, data->vendor, data->type, data->size); |  | ||||||
| 		switch (data->format) { |  | ||||||
| 		case 's': |  | ||||||
| 			memcpy(val, data->data, data->size); |  | ||||||
| 			break; |  | ||||||
| 		case 'x': |  | ||||||
| 			hexstr2bin(data->data, val, data->size); |  | ||||||
| 			break; |  | ||||||
| 		case 'd': |  | ||||||
| 			WPA_PUT_BE32(val, atoi(data->data)); |  | ||||||
| 			break; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| radius_user_parse_methods(struct eap_user *eap, struct blob_attr *data) |  | ||||||
| { |  | ||||||
| 	struct blob_attr *cur; |  | ||||||
| 	int rem, n = 0; |  | ||||||
|  |  | ||||||
| 	if (!data) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	blobmsg_for_each_attr(cur, data, rem) { |  | ||||||
| 		const char *method; |  | ||||||
|  |  | ||||||
| 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		if (n == EAP_MAX_METHODS) |  | ||||||
| 			break; |  | ||||||
|  |  | ||||||
| 		method = blobmsg_get_string(cur); |  | ||||||
| 		eap->methods[n].method = eap_server_get_type(method, &eap->methods[n].vendor); |  | ||||||
| 		if (eap->methods[n].vendor == EAP_VENDOR_IETF && |  | ||||||
| 		    eap->methods[n].method == EAP_TYPE_NONE) { |  | ||||||
| 			if (!strcmp(method, "TTLS-PAP")) { |  | ||||||
| 				eap->ttls_auth |= EAP_TTLS_AUTH_PAP; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (!strcmp(method, "TTLS-CHAP")) { |  | ||||||
| 				eap->ttls_auth |= EAP_TTLS_AUTH_CHAP; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (!strcmp(method, "TTLS-MSCHAP")) { |  | ||||||
| 				eap->ttls_auth |= EAP_TTLS_AUTH_MSCHAP; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (!strcmp(method, "TTLS-MSCHAPV2")) { |  | ||||||
| 				eap->ttls_auth |= EAP_TTLS_AUTH_MSCHAPV2; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (!strcmp(method, "MACACL")) { |  | ||||||
| 				eap->macacl = 1; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		n++; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static struct eap_user * |  | ||||||
| radius_user_get_state(struct radius_user_data *u, struct blob_attr *data, |  | ||||||
| 		      const char *id) |  | ||||||
| { |  | ||||||
| 	static const struct blobmsg_policy policy[__USER_ATTR_MAX] = { |  | ||||||
| 		[USER_ATTR_PASSWORD] = { "password", BLOBMSG_TYPE_STRING }, |  | ||||||
| 		[USER_ATTR_HASH] = { "hash", BLOBMSG_TYPE_STRING }, |  | ||||||
| 		[USER_ATTR_SALT] = { "salt", BLOBMSG_TYPE_STRING }, |  | ||||||
| 		[USER_ATTR_METHODS] = { "methods", BLOBMSG_TYPE_ARRAY }, |  | ||||||
| 		[USER_ATTR_RADIUS] = { "radius", BLOBMSG_TYPE_ARRAY }, |  | ||||||
| 		[USER_ATTR_VLAN] = { "vlan-id", BLOBMSG_TYPE_INT32 }, |  | ||||||
| 		[USER_ATTR_MAX_RATE_UP] = { "max-rate-up", BLOBMSG_TYPE_INT32 }, |  | ||||||
| 		[USER_ATTR_MAX_RATE_DOWN] = { "max-rate-down", BLOBMSG_TYPE_INT32 }, |  | ||||||
| 	}; |  | ||||||
| 	struct blob_attr *tb[__USER_ATTR_MAX], *cur; |  | ||||||
| 	char *password_buf, *salt_buf, *name_buf; |  | ||||||
| 	struct radius_parse_attr_state astate = {}; |  | ||||||
| 	struct hostapd_radius_attr *attr; |  | ||||||
| 	struct radius_user_state *state; |  | ||||||
| 	int pw_len = 0, salt_len = 0; |  | ||||||
| 	struct eap_user *eap; |  | ||||||
| 	struct wpabuf *val; |  | ||||||
| 	size_t attrsize = 0; |  | ||||||
| 	void *attrdata; |  | ||||||
| 	int n_attr = 0; |  | ||||||
|  |  | ||||||
| 	state = avl_find_element(&u->user_state, id, state, node); |  | ||||||
| 	if (state) |  | ||||||
| 		return &state->data; |  | ||||||
|  |  | ||||||
| 	blobmsg_parse(policy, __USER_ATTR_MAX, tb, blobmsg_data(data), blobmsg_len(data)); |  | ||||||
|  |  | ||||||
| 	if ((cur = tb[USER_ATTR_SALT]) != NULL) |  | ||||||
| 		salt_len = strlen(blobmsg_get_string(cur)) / 2; |  | ||||||
| 	if ((cur = tb[USER_ATTR_HASH]) != NULL) |  | ||||||
| 		pw_len = strlen(blobmsg_get_string(cur)) / 2; |  | ||||||
| 	else if ((cur = tb[USER_ATTR_PASSWORD]) != NULL) |  | ||||||
| 		pw_len = blobmsg_len(cur) - 1; |  | ||||||
| 	radius_count_attrs(tb, &n_attr, &attrsize); |  | ||||||
|  |  | ||||||
| 	state = calloc_a(sizeof(*state), &name_buf, strlen(id) + 1, |  | ||||||
| 			 &password_buf, pw_len, |  | ||||||
| 			 &salt_buf, salt_len, |  | ||||||
| 			 &astate.attr, n_attr * sizeof(*astate.attr), |  | ||||||
| 			 &astate.buf, n_attr * sizeof(*astate.buf), |  | ||||||
| 			 &astate.attrdata, attrsize); |  | ||||||
| 	eap = &state->data; |  | ||||||
| 	eap->salt = salt_len ? salt_buf : NULL; |  | ||||||
| 	eap->salt_len = salt_len; |  | ||||||
| 	eap->password = pw_len ? password_buf : NULL; |  | ||||||
| 	eap->password_len = pw_len; |  | ||||||
| 	eap->force_version = -1; |  | ||||||
|  |  | ||||||
| 	if ((cur = tb[USER_ATTR_SALT]) != NULL) |  | ||||||
| 		hexstr2bin(blobmsg_get_string(cur), salt_buf, salt_len); |  | ||||||
| 	if ((cur = tb[USER_ATTR_PASSWORD]) != NULL) |  | ||||||
| 		memcpy(password_buf, blobmsg_get_string(cur), pw_len); |  | ||||||
| 	else if ((cur = tb[USER_ATTR_HASH]) != NULL) { |  | ||||||
| 		hexstr2bin(blobmsg_get_string(cur), password_buf, pw_len); |  | ||||||
| 		eap->password_hash = 1; |  | ||||||
| 	} |  | ||||||
| 	radius_user_parse_methods(eap, tb[USER_ATTR_METHODS]); |  | ||||||
|  |  | ||||||
| 	if (n_attr > 0) { |  | ||||||
| 		cur = tb[USER_ATTR_RADIUS]; |  | ||||||
| 		eap->accept_attr = astate.attr; |  | ||||||
| 		radius_parse_attrs(tb, &astate); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	state->node.key = strcpy(name_buf, id); |  | ||||||
| 	avl_insert(&u->user_state, &state->node); |  | ||||||
|  |  | ||||||
| 	return &state->data; |  | ||||||
|  |  | ||||||
| free: |  | ||||||
| 	free(state); |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int radius_get_eap_user(void *ctx, const u8 *identity, |  | ||||||
| 			       size_t identity_len, int phase2, |  | ||||||
| 			       struct eap_user *user) |  | ||||||
| { |  | ||||||
| 	struct radius_state *s = ctx; |  | ||||||
| 	struct radius_user_data *u = phase2 ? &s->phase2 : &s->phase1; |  | ||||||
| 	struct blob_attr *entry; |  | ||||||
| 	struct eap_user *data; |  | ||||||
| 	char *id; |  | ||||||
|  |  | ||||||
| 	if (identity_len > 512) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	load_userfile(s); |  | ||||||
|  |  | ||||||
| 	id = alloca(identity_len + 1); |  | ||||||
| 	memcpy(id, identity, identity_len); |  | ||||||
| 	id[identity_len] = 0; |  | ||||||
|  |  | ||||||
| 	entry = radius_user_get(u, id); |  | ||||||
| 	if (!entry) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	if (!user) |  | ||||||
| 		return 0; |  | ||||||
|  |  | ||||||
| 	data = radius_user_get_state(u, entry, id); |  | ||||||
| 	if (!data) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	*user = *data; |  | ||||||
| 	if (user->password_len > 0) |  | ||||||
| 		user->password = os_memdup(user->password, user->password_len); |  | ||||||
| 	if (user->salt_len > 0) |  | ||||||
| 		user->salt = os_memdup(user->salt, user->salt_len); |  | ||||||
| 	user->phase2 = phase2; |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int radius_setup(struct radius_state *s, struct radius_config *c) |  | ||||||
| { |  | ||||||
| 	struct eap_config *eap = &s->eap; |  | ||||||
| 	struct tls_config conf = { |  | ||||||
| 		.event_cb = radius_tls_event, |  | ||||||
| 		.tls_flags = TLS_CONN_DISABLE_TLSv1_3, |  | ||||||
| 		.cb_ctx = s, |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	eap->eap_server = 1; |  | ||||||
| 	eap->max_auth_rounds = 100; |  | ||||||
| 	eap->max_auth_rounds_short = 50; |  | ||||||
| 	eap->ssl_ctx = tls_init(&conf); |  | ||||||
| 	if (!eap->ssl_ctx) { |  | ||||||
| 		wpa_printf(MSG_INFO, "TLS init failed\n"); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (tls_global_set_params(eap->ssl_ctx, &c->tls)) { |  | ||||||
| 		wpa_printf(MSG_INFO, "failed to set TLS parameters\n"); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	c->radius.eap_cfg = eap; |  | ||||||
| 	c->radius.conf_ctx = s; |  | ||||||
| 	c->radius.get_eap_user = radius_get_eap_user; |  | ||||||
| 	s->radius = radius_server_init(&c->radius); |  | ||||||
| 	if (!s->radius) { |  | ||||||
| 		wpa_printf(MSG_INFO, "failed to initialize radius server\n"); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int radius_init(struct radius_state *s) |  | ||||||
| { |  | ||||||
| 	memset(s, 0, sizeof(*s)); |  | ||||||
| 	radius_userdata_init(&s->phase1); |  | ||||||
| 	radius_userdata_init(&s->phase2); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void radius_deinit(struct radius_state *s) |  | ||||||
| { |  | ||||||
| 	if (s->radius) |  | ||||||
| 		radius_server_deinit(s->radius); |  | ||||||
|  |  | ||||||
| 	if (s->eap.ssl_ctx) |  | ||||||
| 		tls_deinit(s->eap.ssl_ctx); |  | ||||||
|  |  | ||||||
| 	radius_userdata_free(&s->phase1); |  | ||||||
| 	radius_userdata_free(&s->phase2); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int usage(const char *progname) |  | ||||||
| { |  | ||||||
| 	fprintf(stderr, "Usage: %s <options>\n", |  | ||||||
| 		progname); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int radius_main(int argc, char **argv) |  | ||||||
| { |  | ||||||
| 	static struct radius_state state = {}; |  | ||||||
| 	static struct radius_config config = {}; |  | ||||||
| 	const char *progname = argv[0]; |  | ||||||
| 	int ret = 0; |  | ||||||
| 	int ch; |  | ||||||
|  |  | ||||||
| 	wpa_debug_setup_stdout(); |  | ||||||
| 	wpa_debug_level = 0; |  | ||||||
|  |  | ||||||
| 	if (eloop_init()) { |  | ||||||
| 		wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	eap_server_register_methods(); |  | ||||||
| 	radius_init(&state); |  | ||||||
|  |  | ||||||
| 	while ((ch = getopt(argc, argv, "6C:c:d:i:k:K:p:P:s:u:")) != -1) { |  | ||||||
| 		switch (ch) { |  | ||||||
| 		case '6': |  | ||||||
| 			config.radius.ipv6 = 1; |  | ||||||
| 			break; |  | ||||||
| 		case 'C': |  | ||||||
| 			config.tls.ca_cert = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'c': |  | ||||||
| 			if (config.tls.client_cert2) |  | ||||||
| 				return usage(progname); |  | ||||||
|  |  | ||||||
| 			if (config.tls.client_cert) |  | ||||||
| 				config.tls.client_cert2 = optarg; |  | ||||||
| 			else |  | ||||||
| 				config.tls.client_cert = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'd': |  | ||||||
| 			config.tls.dh_file = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'i': |  | ||||||
| 			state.eap.server_id = optarg; |  | ||||||
| 			state.eap.server_id_len = strlen(optarg); |  | ||||||
| 			break; |  | ||||||
| 		case 'k': |  | ||||||
| 			if (config.tls.private_key2) |  | ||||||
| 				return usage(progname); |  | ||||||
|  |  | ||||||
| 			if (config.tls.private_key) |  | ||||||
| 				config.tls.private_key2 = optarg; |  | ||||||
| 			else |  | ||||||
| 				config.tls.private_key = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'K': |  | ||||||
| 			if (config.tls.private_key_passwd2) |  | ||||||
| 				return usage(progname); |  | ||||||
|  |  | ||||||
| 			if (config.tls.private_key_passwd) |  | ||||||
| 				config.tls.private_key_passwd2 = optarg; |  | ||||||
| 			else |  | ||||||
| 				config.tls.private_key_passwd = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'p': |  | ||||||
| 			config.radius.auth_port = atoi(optarg); |  | ||||||
| 			break; |  | ||||||
| 		case 'P': |  | ||||||
| 			config.radius.acct_port = atoi(optarg); |  | ||||||
| 			break; |  | ||||||
| 		case 's': |  | ||||||
| 			config.radius.client_file = optarg; |  | ||||||
| 			break; |  | ||||||
| 		case 'u': |  | ||||||
| 			state.user_file = optarg; |  | ||||||
| 			break; |  | ||||||
| 		default: |  | ||||||
| 			return usage(progname); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (!config.tls.client_cert || !config.tls.private_key || |  | ||||||
| 	    !config.radius.client_file || !state.eap.server_id || |  | ||||||
| 	    !state.user_file) { |  | ||||||
| 		wpa_printf(MSG_INFO, "missing options\n"); |  | ||||||
| 		goto out; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ret = radius_setup(&state, &config); |  | ||||||
| 	if (ret) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	load_userfile(&state); |  | ||||||
| 	eloop_run(); |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	radius_deinit(&state); |  | ||||||
| 	os_program_deinit(); |  | ||||||
|  |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,144 +0,0 @@ | |||||||
| /* |  | ||||||
|  * hostapd / ubus support |  | ||||||
|  * Copyright (c) 2013, Felix Fietkau <nbd@nbd.name> |  | ||||||
|  * |  | ||||||
|  * This software may be distributed under the terms of the BSD license. |  | ||||||
|  * See README for more details. |  | ||||||
|  */ |  | ||||||
| #ifndef __HOSTAPD_UBUS_H |  | ||||||
| #define __HOSTAPD_UBUS_H |  | ||||||
|  |  | ||||||
| enum hostapd_ubus_event_type { |  | ||||||
| 	HOSTAPD_UBUS_PROBE_REQ, |  | ||||||
| 	HOSTAPD_UBUS_AUTH_REQ, |  | ||||||
| 	HOSTAPD_UBUS_ASSOC_REQ, |  | ||||||
| 	HOSTAPD_UBUS_COA, |  | ||||||
| 	HOSTAPD_UBUS_TYPE_MAX |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct hostapd_ubus_request { |  | ||||||
| 	enum hostapd_ubus_event_type type; |  | ||||||
| 	const struct ieee80211_mgmt *mgmt_frame; |  | ||||||
| 	const struct ieee802_11_elems *elems; |  | ||||||
| 	int ssi_signal; /* dBm */ |  | ||||||
| 	const u8 *addr; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct hostapd_iface; |  | ||||||
| struct hostapd_data; |  | ||||||
| struct hapd_interfaces; |  | ||||||
| struct rrm_measurement_beacon_report; |  | ||||||
|  |  | ||||||
| #ifdef UBUS_SUPPORT |  | ||||||
|  |  | ||||||
| #include <libubox/avl.h> |  | ||||||
| #include <libubus.h> |  | ||||||
|  |  | ||||||
| struct hostapd_ubus_bss { |  | ||||||
| 	struct ubus_object obj; |  | ||||||
| 	struct avl_tree banned; |  | ||||||
| 	int notify_response; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| void hostapd_ubus_add_iface(struct hostapd_iface *iface); |  | ||||||
| void hostapd_ubus_free_iface(struct hostapd_iface *iface); |  | ||||||
| void hostapd_ubus_add_bss(struct hostapd_data *hapd); |  | ||||||
| void hostapd_ubus_free_bss(struct hostapd_data *hapd); |  | ||||||
| void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan); |  | ||||||
| void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan); |  | ||||||
|  |  | ||||||
| int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req); |  | ||||||
| void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac); |  | ||||||
| void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta); |  | ||||||
| void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, |  | ||||||
| 				       const u8 *addr, u8 token, u8 rep_mode, |  | ||||||
| 				       struct rrm_measurement_beacon_report *rep, |  | ||||||
| 				       size_t len); |  | ||||||
| void hostapd_ubus_notify_radar_detected(struct hostapd_iface *iface, int frequency, |  | ||||||
| 					int chan_width, int cf1, int cf2); |  | ||||||
| void hostapd_ubus_notify_rssi(struct hostapd_data *hapd, const char *type, const u8 *addr, int rssi); |  | ||||||
|  |  | ||||||
| void hostapd_ubus_notify_bss_transition_response( |  | ||||||
| 	struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 status_code, |  | ||||||
| 	u8 bss_termination_delay, const u8 *target_bssid, |  | ||||||
| 	const u8 *candidate_list, u16 candidate_list_len); |  | ||||||
| void hostapd_ubus_add(struct hapd_interfaces *interfaces); |  | ||||||
| void hostapd_ubus_free(struct hapd_interfaces *interfaces); |  | ||||||
| int hostapd_ubus_notify_bss_transition_query( |  | ||||||
| 	struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, |  | ||||||
| 	const u8 *candidate_list, u16 candidate_list_len); |  | ||||||
| void hostapd_ubus_notify_csa(struct hostapd_data *hapd, int freq); |  | ||||||
|  |  | ||||||
| #else |  | ||||||
|  |  | ||||||
| struct hostapd_ubus_bss {}; |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_add_iface(struct hostapd_iface *iface) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_free_iface(struct hostapd_iface *iface) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_add_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_free_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req) |  | ||||||
| { |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, |  | ||||||
| 						     const u8 *addr, u8 token, |  | ||||||
| 						     u8 rep_mode, |  | ||||||
| 						     struct rrm_measurement_beacon_report *rep, |  | ||||||
| 						     size_t len) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline void hostapd_ubus_notify_radar_detected(struct hostapd_iface *iface, int frequency, |  | ||||||
| 						      int chan_width, int cf1, int cf2) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_notify_bss_transition_response( |  | ||||||
| 	struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 status_code, |  | ||||||
| 	u8 bss_termination_delay, const u8 *target_bssid, |  | ||||||
| 	const u8 *candidate_list, u16 candidate_list_len) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_add(struct hapd_interfaces *interfaces) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline void hostapd_ubus_free(struct hapd_interfaces *interfaces) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline int hostapd_ubus_notify_bss_transition_query( |  | ||||||
| 	struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, |  | ||||||
| 	const u8 *candidate_list, u16 candidate_list_len) |  | ||||||
| { |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #endif |  | ||||||
| @@ -1,952 +0,0 @@ | |||||||
| #include <sys/un.h> |  | ||||||
|  |  | ||||||
| #include "utils/includes.h" |  | ||||||
| #include "utils/common.h" |  | ||||||
| #include "utils/ucode.h" |  | ||||||
| #include "hostapd.h" |  | ||||||
| #include "beacon.h" |  | ||||||
| #include "hw_features.h" |  | ||||||
| #include "ap_drv_ops.h" |  | ||||||
| #include "dfs.h" |  | ||||||
| #include "acs.h" |  | ||||||
| #include "ieee802_11_auth.h" |  | ||||||
| #include <libubox/uloop.h> |  | ||||||
|  |  | ||||||
| static uc_resource_type_t *global_type, *bss_type, *iface_type; |  | ||||||
| static struct hapd_interfaces *interfaces; |  | ||||||
| static uc_value_t *global, *bss_registry, *iface_registry; |  | ||||||
| static uc_vm_t *vm; |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| hostapd_ucode_bss_get_uval(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (hapd->ucode.idx) |  | ||||||
| 		return wpa_ucode_registry_get(bss_registry, hapd->ucode.idx); |  | ||||||
|  |  | ||||||
| 	val = uc_resource_new(bss_type, hapd); |  | ||||||
| 	hapd->ucode.idx = wpa_ucode_registry_add(bss_registry, val); |  | ||||||
|  |  | ||||||
| 	return val; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| hostapd_ucode_iface_get_uval(struct hostapd_iface *hapd) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (hapd->ucode.idx) |  | ||||||
| 		return wpa_ucode_registry_get(iface_registry, hapd->ucode.idx); |  | ||||||
|  |  | ||||||
| 	val = uc_resource_new(iface_type, hapd); |  | ||||||
| 	hapd->ucode.idx = wpa_ucode_registry_add(iface_registry, val); |  | ||||||
|  |  | ||||||
| 	return val; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| hostapd_ucode_update_bss_list(struct hostapd_iface *iface, uc_value_t *if_bss, uc_value_t *bss) |  | ||||||
| { |  | ||||||
| 	uc_value_t *list; |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	list = ucv_array_new(vm); |  | ||||||
| 	for (i = 0; iface->bss && i < iface->num_bss; i++) { |  | ||||||
| 		struct hostapd_data *hapd = iface->bss[i]; |  | ||||||
| 		uc_value_t *val = hostapd_ucode_bss_get_uval(hapd); |  | ||||||
|  |  | ||||||
| 		ucv_array_set(list, i, ucv_get(ucv_string_new(hapd->conf->iface))); |  | ||||||
| 		ucv_object_add(bss, hapd->conf->iface, ucv_get(val)); |  | ||||||
| 	} |  | ||||||
| 	ucv_object_add(if_bss, iface->phy, ucv_get(list)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| hostapd_ucode_update_interfaces(void) |  | ||||||
| { |  | ||||||
| 	uc_value_t *ifs = ucv_object_new(vm); |  | ||||||
| 	uc_value_t *if_bss = ucv_array_new(vm); |  | ||||||
| 	uc_value_t *bss = ucv_object_new(vm); |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < interfaces->count; i++) { |  | ||||||
| 		struct hostapd_iface *iface = interfaces->iface[i]; |  | ||||||
|  |  | ||||||
| 		ucv_object_add(ifs, iface->phy, ucv_get(hostapd_ucode_iface_get_uval(iface))); |  | ||||||
| 		hostapd_ucode_update_bss_list(iface, if_bss, bss); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ucv_object_add(ucv_prototype_get(global), "interfaces", ucv_get(ifs)); |  | ||||||
| 	ucv_object_add(ucv_prototype_get(global), "interface_bss", ucv_get(if_bss)); |  | ||||||
| 	ucv_object_add(ucv_prototype_get(global), "bss", ucv_get(bss)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_add_iface(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	uc_value_t *iface = uc_fn_arg(0); |  | ||||||
| 	int ret; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(iface) != UC_STRING) |  | ||||||
| 		return ucv_int64_new(-1); |  | ||||||
|  |  | ||||||
| 	ret = hostapd_add_iface(interfaces, ucv_string_get(iface)); |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
|  |  | ||||||
| 	return ucv_int64_new(ret); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_remove_iface(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	uc_value_t *iface = uc_fn_arg(0); |  | ||||||
|  |  | ||||||
| 	if (ucv_type(iface) != UC_STRING) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	hostapd_remove_iface(interfaces, ucv_string_get(iface)); |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static struct hostapd_vlan * |  | ||||||
| bss_conf_find_vlan(struct hostapd_bss_config *bss, int id) |  | ||||||
| { |  | ||||||
| 	struct hostapd_vlan *vlan; |  | ||||||
|  |  | ||||||
| 	for (vlan = bss->vlan; vlan; vlan = vlan->next) |  | ||||||
| 		if (vlan->vlan_id == id) |  | ||||||
| 			return vlan; |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int |  | ||||||
| bss_conf_rename_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan, |  | ||||||
| 		     const char *ifname) |  | ||||||
| { |  | ||||||
| 	if (!strcmp(ifname, vlan->ifname)) |  | ||||||
| 		return 0; |  | ||||||
|  |  | ||||||
| 	hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, vlan->ifname, ifname); |  | ||||||
| 	os_strlcpy(vlan->ifname, ifname, sizeof(vlan->ifname)); |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static int |  | ||||||
| bss_reload_vlans(struct hostapd_data *hapd, struct hostapd_bss_config *bss) |  | ||||||
| { |  | ||||||
| 	struct hostapd_bss_config *old_bss = hapd->conf; |  | ||||||
| 	struct hostapd_vlan *vlan, *vlan_new, *wildcard; |  | ||||||
| 	char ifname[IFNAMSIZ + 1], vlan_ifname[IFNAMSIZ + 1], *pos; |  | ||||||
| 	int ret; |  | ||||||
|  |  | ||||||
| 	vlan = bss_conf_find_vlan(old_bss, VLAN_ID_WILDCARD); |  | ||||||
| 	wildcard = bss_conf_find_vlan(bss, VLAN_ID_WILDCARD); |  | ||||||
| 	if (!!vlan != !!wildcard) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	if (vlan && wildcard && strcmp(vlan->ifname, wildcard->ifname) != 0) |  | ||||||
| 		strcpy(vlan->ifname, wildcard->ifname); |  | ||||||
| 	else |  | ||||||
| 		wildcard = NULL; |  | ||||||
|  |  | ||||||
| 	for (vlan = bss->vlan; vlan; vlan = vlan->next) { |  | ||||||
| 		if (vlan->vlan_id == VLAN_ID_WILDCARD || |  | ||||||
| 		    vlan->dynamic_vlan > 0) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		if (!bss_conf_find_vlan(old_bss, vlan->vlan_id)) |  | ||||||
| 			return -1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for (vlan = old_bss->vlan; vlan; vlan = vlan->next) { |  | ||||||
| 		if (vlan->vlan_id == VLAN_ID_WILDCARD) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		if (vlan->dynamic_vlan == 0) { |  | ||||||
| 			vlan_new = bss_conf_find_vlan(bss, vlan->vlan_id); |  | ||||||
| 			if (!vlan_new) |  | ||||||
| 				return -1; |  | ||||||
|  |  | ||||||
| 			if (bss_conf_rename_vlan(hapd, vlan, vlan_new->ifname)) |  | ||||||
| 				return -1; |  | ||||||
|  |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (!wildcard) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		os_strlcpy(ifname, wildcard->ifname, sizeof(ifname)); |  | ||||||
| 		pos = os_strchr(ifname, '#'); |  | ||||||
| 		if (!pos) |  | ||||||
| 			return -1; |  | ||||||
|  |  | ||||||
| 		*pos++ = '\0'; |  | ||||||
| 		ret = os_snprintf(vlan_ifname, sizeof(vlan_ifname), "%s%d%s", |  | ||||||
| 				  ifname, vlan->vlan_id, pos); |  | ||||||
| 	        if (os_snprintf_error(sizeof(vlan_ifname), ret)) |  | ||||||
| 			return -1; |  | ||||||
|  |  | ||||||
| 		if (bss_conf_rename_vlan(hapd, vlan, vlan_ifname)) |  | ||||||
| 			return -1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); |  | ||||||
| 	struct hostapd_bss_config *old_bss; |  | ||||||
| 	struct hostapd_iface *iface; |  | ||||||
| 	struct hostapd_config *conf; |  | ||||||
| 	uc_value_t *file = uc_fn_arg(0); |  | ||||||
| 	uc_value_t *index = uc_fn_arg(1); |  | ||||||
| 	uc_value_t *files_only = uc_fn_arg(2); |  | ||||||
| 	unsigned int i, idx = 0; |  | ||||||
| 	int ret = -1; |  | ||||||
|  |  | ||||||
| 	if (!hapd || ucv_type(file) != UC_STRING) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(index) == UC_INTEGER) |  | ||||||
| 		idx = ucv_int64_get(index); |  | ||||||
|  |  | ||||||
| 	iface = hapd->iface; |  | ||||||
| 	conf = interfaces->config_read_cb(ucv_string_get(file)); |  | ||||||
| 	if (!conf) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	if (idx > conf->num_bss || !conf->bss[idx]) |  | ||||||
| 		goto free; |  | ||||||
|  |  | ||||||
| 	if (ucv_boolean_get(files_only)) { |  | ||||||
| 		struct hostapd_bss_config *bss = conf->bss[idx]; |  | ||||||
| 		struct hostapd_bss_config *old_bss = hapd->conf; |  | ||||||
|  |  | ||||||
| #define swap_field(name)				\ |  | ||||||
| 	do {								\ |  | ||||||
| 		void *ptr = old_bss->name;		\ |  | ||||||
| 		old_bss->name = bss->name;		\ |  | ||||||
| 		bss->name = ptr;				\ |  | ||||||
| 	} while (0) |  | ||||||
|  |  | ||||||
| 		swap_field(ssid.wpa_psk_file); |  | ||||||
| 		ret = bss_reload_vlans(hapd, bss); |  | ||||||
| 		goto done; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	hostapd_bss_deinit_no_free(hapd); |  | ||||||
| 	hostapd_drv_stop_ap(hapd); |  | ||||||
| 	hostapd_free_hapd_data(hapd); |  | ||||||
|  |  | ||||||
| 	old_bss = hapd->conf; |  | ||||||
| 	for (i = 0; i < iface->conf->num_bss; i++) |  | ||||||
| 		if (iface->conf->bss[i] == hapd->conf) |  | ||||||
| 			iface->conf->bss[i] = conf->bss[idx]; |  | ||||||
| 	hapd->conf = conf->bss[idx]; |  | ||||||
| 	conf->bss[idx] = old_bss; |  | ||||||
|  |  | ||||||
| 	hostapd_setup_bss(hapd, hapd == iface->bss[0], true); |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
| 	hostapd_owe_update_trans(iface); |  | ||||||
|  |  | ||||||
| done: |  | ||||||
| 	ret = 0; |  | ||||||
| free: |  | ||||||
| 	hostapd_config_free(conf); |  | ||||||
| out: |  | ||||||
| 	return ucv_int64_new(ret); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| hostapd_remove_iface_bss_conf(struct hostapd_config *iconf, |  | ||||||
| 			      struct hostapd_bss_config *conf) |  | ||||||
| { |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < iconf->num_bss; i++) |  | ||||||
| 		if (iconf->bss[i] == conf) |  | ||||||
| 			break; |  | ||||||
|  |  | ||||||
| 	if (i == iconf->num_bss) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	for (i++; i < iconf->num_bss; i++) |  | ||||||
| 		iconf->bss[i - 1] = iconf->bss[i]; |  | ||||||
| 	iconf->num_bss--; |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_bss_delete(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); |  | ||||||
| 	struct hostapd_iface *iface; |  | ||||||
| 	int i, idx; |  | ||||||
|  |  | ||||||
| 	if (!hapd) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	iface = hapd->iface; |  | ||||||
| 	if (iface->num_bss == 1) { |  | ||||||
| 		wpa_printf(MSG_ERROR, "trying to delete last bss of an iface: %s\n", hapd->conf->iface); |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for (idx = 0; idx < iface->num_bss; idx++) |  | ||||||
| 		if (iface->bss[idx] == hapd) |  | ||||||
| 			break; |  | ||||||
|  |  | ||||||
| 	if (idx == iface->num_bss) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	for (i = idx + 1; i < iface->num_bss; i++) |  | ||||||
| 		iface->bss[i - 1] = iface->bss[i]; |  | ||||||
|  |  | ||||||
| 	iface->num_bss--; |  | ||||||
|  |  | ||||||
| 	iface->bss[0]->interface_added = 0; |  | ||||||
| 	hostapd_drv_set_first_bss(iface->bss[0]); |  | ||||||
| 	hapd->interface_added = 1; |  | ||||||
|  |  | ||||||
| 	hostapd_drv_stop_ap(hapd); |  | ||||||
| 	hostapd_bss_deinit(hapd); |  | ||||||
| 	hostapd_remove_iface_bss_conf(iface->conf, hapd->conf); |  | ||||||
| 	hostapd_config_free_bss(hapd->conf); |  | ||||||
| 	os_free(hapd); |  | ||||||
|  |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_iface_add_bss(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); |  | ||||||
| 	struct hostapd_bss_config *bss; |  | ||||||
| 	struct hostapd_config *conf; |  | ||||||
| 	struct hostapd_data *hapd; |  | ||||||
| 	uc_value_t *file = uc_fn_arg(0); |  | ||||||
| 	uc_value_t *index = uc_fn_arg(1); |  | ||||||
| 	unsigned int idx = 0; |  | ||||||
| 	uc_value_t *ret = NULL; |  | ||||||
|  |  | ||||||
| 	if (!iface || ucv_type(file) != UC_STRING) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(index) == UC_INTEGER) |  | ||||||
| 		idx = ucv_int64_get(index); |  | ||||||
|  |  | ||||||
| 	conf = interfaces->config_read_cb(ucv_string_get(file)); |  | ||||||
| 	if (!conf || idx > conf->num_bss || !conf->bss[idx]) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	bss = conf->bss[idx]; |  | ||||||
| 	hapd = hostapd_alloc_bss_data(iface, iface->conf, bss); |  | ||||||
| 	if (!hapd) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	hapd->driver = iface->bss[0]->driver; |  | ||||||
| 	hapd->drv_priv = iface->bss[0]->drv_priv; |  | ||||||
| 	if (interfaces->ctrl_iface_init && |  | ||||||
| 	    interfaces->ctrl_iface_init(hapd) < 0) |  | ||||||
| 		goto free_hapd; |  | ||||||
|  |  | ||||||
| 	if (iface->state == HAPD_IFACE_ENABLED && |  | ||||||
| 	    hostapd_setup_bss(hapd, -1, true)) |  | ||||||
| 		goto deinit_ctrl; |  | ||||||
|  |  | ||||||
| 	iface->bss = os_realloc_array(iface->bss, iface->num_bss + 1, |  | ||||||
| 				      sizeof(*iface->bss)); |  | ||||||
| 	iface->bss[iface->num_bss++] = hapd; |  | ||||||
|  |  | ||||||
| 	iface->conf->bss = os_realloc_array(iface->conf->bss, |  | ||||||
| 					    iface->conf->num_bss + 1, |  | ||||||
| 					    sizeof(*iface->conf->bss)); |  | ||||||
| 	iface->conf->bss[iface->conf->num_bss] = bss; |  | ||||||
| 	conf->bss[idx] = NULL; |  | ||||||
| 	ret = hostapd_ucode_bss_get_uval(hapd); |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
| 	hostapd_owe_update_trans(iface); |  | ||||||
| 	goto out; |  | ||||||
|  |  | ||||||
| deinit_ctrl: |  | ||||||
| 	if (interfaces->ctrl_iface_deinit) |  | ||||||
| 		interfaces->ctrl_iface_deinit(hapd); |  | ||||||
| free_hapd: |  | ||||||
| 	hostapd_free_hapd_data(hapd); |  | ||||||
| 	os_free(hapd); |  | ||||||
| out: |  | ||||||
| 	hostapd_config_free(conf); |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_iface_set_bss_order(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); |  | ||||||
| 	uc_value_t *bss_list = uc_fn_arg(0); |  | ||||||
| 	struct hostapd_data **new_bss; |  | ||||||
| 	struct hostapd_bss_config **new_conf; |  | ||||||
|  |  | ||||||
| 	if (!iface) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(bss_list) != UC_ARRAY || |  | ||||||
| 	    ucv_array_length(bss_list) != iface->num_bss) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	new_bss = calloc(iface->num_bss, sizeof(*new_bss)); |  | ||||||
| 	new_conf = calloc(iface->num_bss, sizeof(*new_conf)); |  | ||||||
| 	for (size_t i = 0; i < iface->num_bss; i++) { |  | ||||||
| 		struct hostapd_data *bss; |  | ||||||
|  |  | ||||||
| 		bss = ucv_resource_data(ucv_array_get(bss_list, i), "hostapd.bss"); |  | ||||||
| 		if (bss->iface != iface) |  | ||||||
| 			goto free; |  | ||||||
|  |  | ||||||
| 		for (size_t k = 0; k < i; k++) |  | ||||||
| 			if (new_bss[k] == bss) |  | ||||||
| 				goto free; |  | ||||||
|  |  | ||||||
| 		new_bss[i] = bss; |  | ||||||
| 		new_conf[i] = bss->conf; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	new_bss[0]->interface_added = 0; |  | ||||||
| 	for (size_t i = 1; i < iface->num_bss; i++) |  | ||||||
| 		new_bss[i]->interface_added = 1; |  | ||||||
|  |  | ||||||
| 	free(iface->bss); |  | ||||||
| 	iface->bss = new_bss; |  | ||||||
|  |  | ||||||
| 	free(iface->conf->bss); |  | ||||||
| 	iface->conf->bss = new_conf; |  | ||||||
| 	iface->conf->num_bss = iface->num_bss; |  | ||||||
| 	hostapd_drv_set_first_bss(iface->bss[0]); |  | ||||||
|  |  | ||||||
| 	return ucv_boolean_new(true); |  | ||||||
|  |  | ||||||
| free: |  | ||||||
| 	free(new_bss); |  | ||||||
| 	free(new_conf); |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_bss_ctrl(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); |  | ||||||
| 	uc_value_t *arg = uc_fn_arg(0); |  | ||||||
| 	struct sockaddr_storage from = {}; |  | ||||||
| 	static char reply[4096]; |  | ||||||
| 	int reply_len; |  | ||||||
|  |  | ||||||
| 	if (!hapd || !interfaces->ctrl_iface_recv || |  | ||||||
| 	    ucv_type(arg) != UC_STRING) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	reply_len = interfaces->ctrl_iface_recv(hapd, ucv_string_get(arg), |  | ||||||
| 						reply, sizeof(reply), |  | ||||||
| 						&from, sizeof(from)); |  | ||||||
| 	if (reply_len < 0) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (reply_len && reply[reply_len - 1] == '\n') |  | ||||||
| 		reply_len--; |  | ||||||
|  |  | ||||||
| 	return ucv_string_new_length(reply, reply_len); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| uc_hostapd_disable_iface(struct hostapd_iface *iface) |  | ||||||
| { |  | ||||||
| 	switch (iface->state) { |  | ||||||
| 	case HAPD_IFACE_DISABLED: |  | ||||||
| 		break; |  | ||||||
| #ifdef CONFIG_ACS |  | ||||||
| 	case HAPD_IFACE_ACS: |  | ||||||
| 		acs_cleanup(iface); |  | ||||||
| 		iface->scan_cb = NULL; |  | ||||||
| 		/* fallthrough */ |  | ||||||
| #endif |  | ||||||
| 	default: |  | ||||||
| 		hostapd_disable_iface(iface); |  | ||||||
| 		break; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	if (!iface) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (iface->state != HAPD_IFACE_ENABLED) |  | ||||||
| 		uc_hostapd_disable_iface(iface); |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < iface->num_bss; i++) { |  | ||||||
| 		struct hostapd_data *hapd = iface->bss[i]; |  | ||||||
|  |  | ||||||
| 		hostapd_drv_stop_ap(hapd); |  | ||||||
| 		hapd->beacon_set_done = 0; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); |  | ||||||
| 	uc_value_t *info = uc_fn_arg(0); |  | ||||||
| 	struct hostapd_config *conf; |  | ||||||
| 	bool changed = false; |  | ||||||
| 	uint64_t intval; |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	if (!iface) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (!info) { |  | ||||||
| 		iface->freq = 0; |  | ||||||
| 		goto out; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (ucv_type(info) != UC_OBJECT) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| #define UPDATE_VAL(field, name)							\ |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, name, NULL))) &&	\ |  | ||||||
| 		!errno && intval != conf->field) do {				\ |  | ||||||
| 		conf->field = intval;						\ |  | ||||||
| 		changed = true;							\ |  | ||||||
| 	} while(0) |  | ||||||
|  |  | ||||||
| 	conf = iface->conf; |  | ||||||
| 	UPDATE_VAL(op_class, "op_class"); |  | ||||||
| 	UPDATE_VAL(hw_mode, "hw_mode"); |  | ||||||
| 	UPDATE_VAL(channel, "channel"); |  | ||||||
| 	UPDATE_VAL(secondary_channel, "sec_channel"); |  | ||||||
| 	if (!changed && |  | ||||||
| 	    (iface->bss[0]->beacon_set_done || |  | ||||||
| 	     iface->state == HAPD_IFACE_DFS)) |  | ||||||
| 		return ucv_boolean_new(true); |  | ||||||
|  |  | ||||||
| 	intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL)); |  | ||||||
| 	if (!errno) |  | ||||||
| 		hostapd_set_oper_centr_freq_seg0_idx(conf, intval); |  | ||||||
|  |  | ||||||
| 	intval = ucv_int64_get(ucv_object_get(info, "center_seg1_idx", NULL)); |  | ||||||
| 	if (!errno) |  | ||||||
| 		hostapd_set_oper_centr_freq_seg1_idx(conf, intval); |  | ||||||
|  |  | ||||||
| 	intval = ucv_int64_get(ucv_object_get(info, "oper_chwidth", NULL)); |  | ||||||
| 	if (!errno) |  | ||||||
| 		hostapd_set_oper_chwidth(conf, intval); |  | ||||||
|  |  | ||||||
| 	intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL)); |  | ||||||
| 	if (!errno) |  | ||||||
| 		iface->freq = intval; |  | ||||||
| 	else |  | ||||||
| 		iface->freq = 0; |  | ||||||
| 	conf->acs = 0; |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	switch (iface->state) { |  | ||||||
| 	case HAPD_IFACE_ENABLED: |  | ||||||
| 		if (!hostapd_is_dfs_required(iface) || |  | ||||||
| 			hostapd_is_dfs_chan_available(iface)) |  | ||||||
| 			break; |  | ||||||
| 		wpa_printf(MSG_INFO, "DFS CAC required on new channel, restart interface"); |  | ||||||
| 		/* fallthrough */ |  | ||||||
| 	default: |  | ||||||
| 		uc_hostapd_disable_iface(iface); |  | ||||||
| 		break; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (conf->channel && !iface->freq) |  | ||||||
| 		iface->freq = hostapd_hw_get_freq(iface->bss[0], conf->channel); |  | ||||||
|  |  | ||||||
| 	if (iface->state != HAPD_IFACE_ENABLED) { |  | ||||||
| 		hostapd_enable_iface(iface); |  | ||||||
| 		return ucv_boolean_new(true); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < iface->num_bss; i++) { |  | ||||||
| 		struct hostapd_data *hapd = iface->bss[i]; |  | ||||||
| 		int ret; |  | ||||||
|  |  | ||||||
| 		hapd->conf->start_disabled = 0; |  | ||||||
| 		hostapd_set_freq(hapd, conf->hw_mode, iface->freq, |  | ||||||
| 				 conf->channel, |  | ||||||
| 				 conf->enable_edmg, |  | ||||||
| 				 conf->edmg_channel, |  | ||||||
| 				 conf->ieee80211n, |  | ||||||
| 				 conf->ieee80211ac, |  | ||||||
| 				 conf->ieee80211ax, |  | ||||||
| 				 conf->ieee80211be, |  | ||||||
| 				 conf->secondary_channel, |  | ||||||
| 				 hostapd_get_oper_chwidth(conf), |  | ||||||
| 				 hostapd_get_oper_centr_freq_seg0_idx(conf), |  | ||||||
| 				 hostapd_get_oper_centr_freq_seg1_idx(conf)); |  | ||||||
|  |  | ||||||
| 		ieee802_11_set_beacon(hapd); |  | ||||||
| 	} |  | ||||||
| 	hostapd_owe_update_trans(iface); |  | ||||||
|  |  | ||||||
| 	return ucv_boolean_new(true); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_iface_switch_channel(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); |  | ||||||
| 	uc_value_t *info = uc_fn_arg(0); |  | ||||||
| 	struct hostapd_config *conf; |  | ||||||
| 	struct csa_settings csa = {}; |  | ||||||
| 	uint64_t intval; |  | ||||||
| 	int i, ret = 0; |  | ||||||
|  |  | ||||||
| 	if (!iface || ucv_type(info) != UC_OBJECT) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	conf = iface->conf; |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, "csa_count", NULL))) && !errno) |  | ||||||
| 		csa.cs_count = intval; |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, "sec_channel", NULL))) && !errno) |  | ||||||
| 		csa.freq_params.sec_channel_offset = intval; |  | ||||||
|  |  | ||||||
| 	csa.freq_params.ht_enabled = conf->ieee80211n; |  | ||||||
| 	csa.freq_params.vht_enabled = conf->ieee80211ac; |  | ||||||
| 	csa.freq_params.he_enabled = conf->ieee80211ax; |  | ||||||
| #ifdef CONFIG_IEEE80211BE |  | ||||||
| 	csa.freq_params.eht_enabled = conf->ieee80211be; |  | ||||||
| #endif |  | ||||||
| 	intval = ucv_int64_get(ucv_object_get(info, "oper_chwidth", NULL)); |  | ||||||
| 	if (errno) |  | ||||||
| 		intval = hostapd_get_oper_chwidth(conf); |  | ||||||
| 	if (intval) |  | ||||||
| 		csa.freq_params.bandwidth = 40 << intval; |  | ||||||
| 	else |  | ||||||
| 		csa.freq_params.bandwidth = csa.freq_params.sec_channel_offset ? 40 : 20; |  | ||||||
|  |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL))) && !errno) |  | ||||||
| 		csa.freq_params.freq = intval; |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, "center_freq1", NULL))) && !errno) |  | ||||||
| 		csa.freq_params.center_freq1 = intval; |  | ||||||
| 	if ((intval = ucv_int64_get(ucv_object_get(info, "center_freq2", NULL))) && !errno) |  | ||||||
| 		csa.freq_params.center_freq2 = intval; |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < iface->num_bss; i++) |  | ||||||
| 		ret = hostapd_switch_channel(iface->bss[i], &csa); |  | ||||||
|  |  | ||||||
| 	return ucv_boolean_new(!ret); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_hostapd_bss_rename(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); |  | ||||||
| 	uc_value_t *ifname_arg = uc_fn_arg(0); |  | ||||||
| 	char prev_ifname[IFNAMSIZ + 1]; |  | ||||||
| 	struct sta_info *sta; |  | ||||||
| 	const char *ifname; |  | ||||||
| 	int ret; |  | ||||||
|  |  | ||||||
| 	if (!hapd || ucv_type(ifname_arg) != UC_STRING) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	os_strlcpy(prev_ifname, hapd->conf->iface, sizeof(prev_ifname)); |  | ||||||
| 	ifname = ucv_string_get(ifname_arg); |  | ||||||
|  |  | ||||||
| 	hostapd_ubus_free_bss(hapd); |  | ||||||
| 	if (interfaces->ctrl_iface_deinit) |  | ||||||
| 		interfaces->ctrl_iface_deinit(hapd); |  | ||||||
|  |  | ||||||
| 	ret = hostapd_drv_if_rename(hapd, WPA_IF_AP_BSS, NULL, ifname); |  | ||||||
| 	if (ret) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	for (sta = hapd->sta_list; sta; sta = sta->next) { |  | ||||||
| 		char cur_name[IFNAMSIZ + 1], new_name[IFNAMSIZ + 1]; |  | ||||||
|  |  | ||||||
| 		if (!(sta->flags & WLAN_STA_WDS) || sta->pending_wds_enable) |  | ||||||
| 			continue; |  | ||||||
|  |  | ||||||
| 		snprintf(cur_name, sizeof(cur_name), "%s.sta%d", prev_ifname, sta->aid); |  | ||||||
| 		snprintf(new_name, sizeof(new_name), "%s.sta%d", ifname, sta->aid); |  | ||||||
| 		hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, cur_name, new_name); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (!strncmp(hapd->conf->ssid.vlan, hapd->conf->iface, sizeof(hapd->conf->ssid.vlan))) |  | ||||||
| 		os_strlcpy(hapd->conf->ssid.vlan, ifname, sizeof(hapd->conf->ssid.vlan)); |  | ||||||
| 	os_strlcpy(hapd->conf->iface, ifname, sizeof(hapd->conf->iface)); |  | ||||||
| 	hostapd_ubus_add_bss(hapd); |  | ||||||
|  |  | ||||||
| 	hostapd_ucode_update_interfaces(); |  | ||||||
| 	hostapd_owe_update_trans(hapd->iface); |  | ||||||
| out: |  | ||||||
| 	if (interfaces->ctrl_iface_init) |  | ||||||
| 		interfaces->ctrl_iface_init(hapd); |  | ||||||
|  |  | ||||||
| 	return ret ? NULL : ucv_boolean_new(true); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int hostapd_ucode_sta_auth(struct hostapd_data *hapd, struct sta_info *sta) |  | ||||||
| { |  | ||||||
| 	char addr[sizeof(MACSTR)]; |  | ||||||
| 	uc_value_t *val, *cur; |  | ||||||
| 	int ret = 0; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("sta_auth")) |  | ||||||
| 		return 0; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(hapd->conf->iface))); |  | ||||||
|  |  | ||||||
| 	snprintf(addr, sizeof(addr), MACSTR, MAC2STR(sta->addr)); |  | ||||||
| 	val = ucv_string_new(addr); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_call(2); |  | ||||||
|  |  | ||||||
| 	cur = ucv_object_get(val, "psk", NULL); |  | ||||||
| 	if (ucv_type(cur) == UC_ARRAY) { |  | ||||||
| 		struct hostapd_sta_wpa_psk_short *p, **next; |  | ||||||
| 		size_t len = ucv_array_length(cur); |  | ||||||
|  |  | ||||||
| 		next = &sta->psk; |  | ||||||
| 		hostapd_free_psk_list(*next); |  | ||||||
| 		*next = NULL; |  | ||||||
|  |  | ||||||
| 		for (size_t i = 0; i < len; i++) { |  | ||||||
| 			uc_value_t *cur_psk; |  | ||||||
| 			const char *str; |  | ||||||
| 			size_t str_len; |  | ||||||
|  |  | ||||||
| 			cur_psk = ucv_array_get(cur, i); |  | ||||||
| 			str = ucv_string_get(cur_psk); |  | ||||||
| 			str_len = strlen(str); |  | ||||||
| 			if (!str || str_len < 8 || str_len > 64) |  | ||||||
| 				continue; |  | ||||||
|  |  | ||||||
| 			p = os_zalloc(sizeof(*p)); |  | ||||||
| 			if (len == 64) { |  | ||||||
| 				if (hexstr2bin(str, p->psk, PMK_LEN) < 0) { |  | ||||||
| 					free(p); |  | ||||||
| 					continue; |  | ||||||
| 				} |  | ||||||
| 			} else { |  | ||||||
| 				p->is_passphrase = 1; |  | ||||||
| 				memcpy(p->passphrase, str, str_len + 1); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			*next = p; |  | ||||||
| 			next = &p->next; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	cur = ucv_object_get(val, "force_psk", NULL); |  | ||||||
| 	sta->use_sta_psk = ucv_is_truish(cur); |  | ||||||
|  |  | ||||||
| 	cur = ucv_object_get(val, "status", NULL); |  | ||||||
| 	if (ucv_type(cur) == UC_INTEGER) |  | ||||||
| 		ret = ucv_int64_get(cur); |  | ||||||
|  |  | ||||||
| 	ucv_put(val); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
|  |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_sta_connected(struct hostapd_data *hapd, struct sta_info *sta) |  | ||||||
| { |  | ||||||
| 	struct hostapd_sta_wpa_psk_short *psk = sta->psk; |  | ||||||
| 	char addr[sizeof(MACSTR)]; |  | ||||||
| 	uc_value_t *val, *cur; |  | ||||||
| 	int ret = 0; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("sta_connected")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(hapd->conf->iface))); |  | ||||||
|  |  | ||||||
| 	snprintf(addr, sizeof(addr), MACSTR, MAC2STR(sta->addr)); |  | ||||||
| 	val = ucv_string_new(addr); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	val = ucv_object_new(vm); |  | ||||||
| 	if (sta->psk_idx) |  | ||||||
| 		ucv_object_add(val, "psk_idx", ucv_int64_new(sta->psk_idx - 1)); |  | ||||||
| 	if (sta->psk) |  | ||||||
| 		ucv_object_add(val, "psk", ucv_string_new(sta->psk->passphrase)); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_call(3); |  | ||||||
| 	if (ucv_type(val) != UC_OBJECT) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	cur = ucv_object_get(val, "vlan", NULL); |  | ||||||
| 	if (ucv_type(cur) == UC_INTEGER) { |  | ||||||
| 		struct vlan_description vdesc = { |  | ||||||
| 			.notempty = 1, |  | ||||||
| 			.untagged = ucv_int64_get(cur), |  | ||||||
| 		}; |  | ||||||
|  |  | ||||||
| 		ap_sta_set_vlan(hapd, sta, &vdesc); |  | ||||||
| 		ap_sta_bind_vlan(hapd, sta); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	ucv_put(val); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int hostapd_ucode_init(struct hapd_interfaces *ifaces) |  | ||||||
| { |  | ||||||
| 	static const uc_function_list_t global_fns[] = { |  | ||||||
| 		{ "printf",	uc_wpa_printf }, |  | ||||||
| 		{ "getpid", uc_wpa_getpid }, |  | ||||||
| 		{ "sha1", uc_wpa_sha1 }, |  | ||||||
| 		{ "freq_info", uc_wpa_freq_info }, |  | ||||||
| 		{ "add_iface", uc_hostapd_add_iface }, |  | ||||||
| 		{ "remove_iface", uc_hostapd_remove_iface }, |  | ||||||
| 	}; |  | ||||||
| 	static const uc_function_list_t bss_fns[] = { |  | ||||||
| 		{ "ctrl", uc_hostapd_bss_ctrl }, |  | ||||||
| 		{ "set_config", uc_hostapd_bss_set_config }, |  | ||||||
| 		{ "rename", uc_hostapd_bss_rename }, |  | ||||||
| 		{ "delete", uc_hostapd_bss_delete }, |  | ||||||
| 	}; |  | ||||||
| 	static const uc_function_list_t iface_fns[] = { |  | ||||||
| 		{ "set_bss_order", uc_hostapd_iface_set_bss_order }, |  | ||||||
| 		{ "add_bss", uc_hostapd_iface_add_bss }, |  | ||||||
| 		{ "stop", uc_hostapd_iface_stop }, |  | ||||||
| 		{ "start", uc_hostapd_iface_start }, |  | ||||||
| 		{ "switch_channel", uc_hostapd_iface_switch_channel }, |  | ||||||
| 	}; |  | ||||||
| 	uc_value_t *data, *proto; |  | ||||||
|  |  | ||||||
| 	interfaces = ifaces; |  | ||||||
| 	vm = wpa_ucode_create_vm(); |  | ||||||
|  |  | ||||||
| 	global_type = uc_type_declare(vm, "hostapd.global", global_fns, NULL); |  | ||||||
| 	bss_type = uc_type_declare(vm, "hostapd.bss", bss_fns, NULL); |  | ||||||
| 	iface_type = uc_type_declare(vm, "hostapd.iface", iface_fns, NULL); |  | ||||||
|  |  | ||||||
| 	bss_registry = ucv_array_new(vm); |  | ||||||
| 	uc_vm_registry_set(vm, "hostap.bss_registry", bss_registry); |  | ||||||
|  |  | ||||||
| 	iface_registry = ucv_array_new(vm); |  | ||||||
| 	uc_vm_registry_set(vm, "hostap.iface_registry", iface_registry); |  | ||||||
|  |  | ||||||
| 	global = wpa_ucode_global_init("hostapd", global_type); |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_run(HOSTAPD_UC_PATH "hostapd.uc")) |  | ||||||
| 		goto free_vm; |  | ||||||
| 	ucv_gc(vm); |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
|  |  | ||||||
| free_vm: |  | ||||||
| 	wpa_ucode_free_vm(); |  | ||||||
| 	return -1; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_free(void) |  | ||||||
| { |  | ||||||
| 	if (wpa_ucode_call_prepare("shutdown") == 0) |  | ||||||
| 		ucv_put(wpa_ucode_call(0)); |  | ||||||
| 	wpa_ucode_free_vm(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_free_iface(struct hostapd_iface *iface) |  | ||||||
| { |  | ||||||
| 	wpa_ucode_registry_remove(iface_registry, iface->ucode.idx); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int hostapd_ucode_afc_request(struct hostapd_iface *iface, const char *request, |  | ||||||
| 			      char *buf, size_t len) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
| 	size_t ret_len; |  | ||||||
| 	int ret = -1; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("afc_request")) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(iface->phy))); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(request))); |  | ||||||
| 	val = wpa_ucode_call(2); |  | ||||||
| 	if (ucv_type(val) != UC_STRING) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	ret_len = ucv_string_length(val); |  | ||||||
| 	if (ret_len >= len) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	memcpy(buf, ucv_string_get(val), ret_len + 1); |  | ||||||
| 	ret = (int)ret_len; |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	ucv_put(val); |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_add_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("bss_add")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	val = hostapd_ucode_bss_get_uval(hapd); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(hapd->conf->iface))); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	ucv_put(wpa_ucode_call(2)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_reload_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("bss_reload")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	val = hostapd_ucode_bss_get_uval(hapd); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(hapd->conf->iface))); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	ucv_put(wpa_ucode_call(2)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void hostapd_ucode_free_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_registry_remove(bss_registry, hapd->ucode.idx); |  | ||||||
| 	if (!val) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	hapd->ucode.idx = 0; |  | ||||||
| 	if (wpa_ucode_call_prepare("bss_remove")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_string_new(hapd->conf->iface)); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	ucv_put(wpa_ucode_call(2)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
| @@ -1,65 +0,0 @@ | |||||||
| #ifndef __HOSTAPD_AP_UCODE_H |  | ||||||
| #define __HOSTAPD_AP_UCODE_H |  | ||||||
|  |  | ||||||
| #include "utils/ucode.h" |  | ||||||
|  |  | ||||||
| struct hostapd_data; |  | ||||||
|  |  | ||||||
| struct hostapd_ucode_bss { |  | ||||||
| #ifdef UCODE_SUPPORT |  | ||||||
| 	int idx; |  | ||||||
| #endif |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct hostapd_ucode_iface { |  | ||||||
| #ifdef UCODE_SUPPORT |  | ||||||
| 	int idx; |  | ||||||
| #endif |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| #ifdef UCODE_SUPPORT |  | ||||||
|  |  | ||||||
| int hostapd_ucode_init(struct hapd_interfaces *ifaces); |  | ||||||
|  |  | ||||||
| void hostapd_ucode_free(void); |  | ||||||
| void hostapd_ucode_free_iface(struct hostapd_iface *iface); |  | ||||||
| int hostapd_ucode_sta_auth(struct hostapd_data *hapd, struct sta_info *sta); |  | ||||||
| void hostapd_ucode_sta_connected(struct hostapd_data *hapd, struct sta_info *sta); |  | ||||||
| void hostapd_ucode_add_bss(struct hostapd_data *hapd); |  | ||||||
| void hostapd_ucode_free_bss(struct hostapd_data *hapd); |  | ||||||
| void hostapd_ucode_reload_bss(struct hostapd_data *hapd); |  | ||||||
| int hostapd_ucode_afc_request(struct hostapd_iface *iface, const char *request, |  | ||||||
| 			      char *buf, size_t len); |  | ||||||
|  |  | ||||||
| #else |  | ||||||
|  |  | ||||||
| static inline int hostapd_ucode_init(struct hapd_interfaces *ifaces) |  | ||||||
| { |  | ||||||
| 	return -EINVAL; |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_free(void) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_free_iface(struct hostapd_iface *iface) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_reload_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline int hostapd_ucode_sta_auth(struct hostapd_data *hapd, struct sta_info *sta) |  | ||||||
| { |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_sta_connected(struct hostapd_data *hapd, struct sta_info *sta) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_add_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| static inline void hostapd_ucode_free_bss(struct hostapd_data *hapd) |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #endif |  | ||||||
| @@ -1,335 +0,0 @@ | |||||||
| #include <unistd.h> |  | ||||||
| #include "ucode.h" |  | ||||||
| #include "utils/eloop.h" |  | ||||||
| #include "crypto/crypto.h" |  | ||||||
| #include "crypto/sha1.h" |  | ||||||
| #include "common/ieee802_11_common.h" |  | ||||||
| #include <libubox/uloop.h> |  | ||||||
| #include <ucode/compiler.h> |  | ||||||
|  |  | ||||||
| static uc_value_t *registry; |  | ||||||
| static uc_vm_t vm; |  | ||||||
| static struct uloop_timeout gc_timer; |  | ||||||
|  |  | ||||||
| static void uc_gc_timer(struct uloop_timeout *timeout) |  | ||||||
| { |  | ||||||
| 	ucv_gc(&vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *uc_wpa_printf(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	uc_value_t *level = uc_fn_arg(0); |  | ||||||
| 	uc_value_t *ret, **args; |  | ||||||
| 	uc_cfn_ptr_t _sprintf; |  | ||||||
| 	int l = MSG_INFO; |  | ||||||
| 	int i, start = 0; |  | ||||||
|  |  | ||||||
| 	_sprintf = uc_stdlib_function("sprintf"); |  | ||||||
| 	if (!sprintf) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(level) == UC_INTEGER) { |  | ||||||
| 		l = ucv_int64_get(level); |  | ||||||
| 		start++; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (nargs <= start) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	ret = _sprintf(vm, nargs - start); |  | ||||||
| 	if (ucv_type(ret) != UC_STRING) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	wpa_printf(l, "%s", ucv_string_get(ret)); |  | ||||||
| 	ucv_put(ret); |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *uc_wpa_freq_info(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	uc_value_t *freq = uc_fn_arg(0); |  | ||||||
| 	uc_value_t *sec = uc_fn_arg(1); |  | ||||||
| 	int width = ucv_uint64_get(uc_fn_arg(2)); |  | ||||||
| 	int freq_val, center_idx, center_ofs; |  | ||||||
| 	enum hostapd_hw_mode hw_mode; |  | ||||||
| 	u8 op_class, channel, tmp_channel; |  | ||||||
| 	const char *modestr; |  | ||||||
| 	int sec_channel = 0; |  | ||||||
| 	uc_value_t *ret; |  | ||||||
| 	int chanwidth; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(freq) != UC_INTEGER) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	freq_val = ucv_int64_get(freq); |  | ||||||
| 	if (ucv_type(sec) == UC_INTEGER) |  | ||||||
| 		sec_channel = ucv_int64_get(sec); |  | ||||||
| 	else if (sec) |  | ||||||
| 		return NULL; |  | ||||||
| 	else if (freq_val > 4000) |  | ||||||
| 		sec_channel = (freq_val / 20) & 1 ? 1 : -1; |  | ||||||
| 	else |  | ||||||
| 		sec_channel = freq_val < 2442 ? 1 : -1; |  | ||||||
|  |  | ||||||
| 	if (sec_channel != -1 && sec_channel != 1 && sec_channel != 0) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	switch (width) { |  | ||||||
| 	case 0: |  | ||||||
| 		chanwidth = CHANWIDTH_USE_HT; |  | ||||||
| 		break; |  | ||||||
| 	case 1: |  | ||||||
| 		chanwidth = CHANWIDTH_80MHZ; |  | ||||||
| 		break; |  | ||||||
| 	case 2: |  | ||||||
| 		chanwidth = CHANWIDTH_160MHZ; |  | ||||||
| 		break; |  | ||||||
| 	default: |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	hw_mode = ieee80211_freq_to_channel_ext(freq_val, sec_channel, |  | ||||||
| 						chanwidth, &op_class, &channel); |  | ||||||
| 	switch (hw_mode) { |  | ||||||
| 	case HOSTAPD_MODE_IEEE80211B: |  | ||||||
| 		modestr = "b"; |  | ||||||
| 		break; |  | ||||||
| 	case HOSTAPD_MODE_IEEE80211G: |  | ||||||
| 		modestr = "g"; |  | ||||||
| 		break; |  | ||||||
| 	case HOSTAPD_MODE_IEEE80211A: |  | ||||||
| 		modestr = "a"; |  | ||||||
| 		break; |  | ||||||
| 	case HOSTAPD_MODE_IEEE80211AD: |  | ||||||
| 		modestr = "ad"; |  | ||||||
| 		break; |  | ||||||
| 	default: |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ret = ucv_object_new(vm); |  | ||||||
| 	ucv_object_add(ret, "op_class", ucv_int64_new(op_class)); |  | ||||||
| 	ucv_object_add(ret, "channel", ucv_int64_new(channel)); |  | ||||||
| 	ucv_object_add(ret, "hw_mode", ucv_int64_new(hw_mode)); |  | ||||||
| 	ucv_object_add(ret, "hw_mode_str", ucv_get(ucv_string_new(modestr))); |  | ||||||
| 	ucv_object_add(ret, "sec_channel", ucv_int64_new(sec_channel)); |  | ||||||
| 	ucv_object_add(ret, "frequency", ucv_int64_new(freq_val)); |  | ||||||
|  |  | ||||||
| 	if (!sec_channel) |  | ||||||
| 		return ret; |  | ||||||
|  |  | ||||||
| 	if (freq_val >= 5900) |  | ||||||
| 		center_ofs = 0; |  | ||||||
| 	else if (freq_val >= 5745) |  | ||||||
| 		center_ofs = 20; |  | ||||||
| 	else |  | ||||||
| 		center_ofs = 35; |  | ||||||
| 	tmp_channel = channel - center_ofs; |  | ||||||
| 	tmp_channel &= ~((8 << width) - 1); |  | ||||||
| 	center_idx = tmp_channel + center_ofs + (4 << width) - 1; |  | ||||||
|  |  | ||||||
| 	if (freq_val < 3000) |  | ||||||
| 		ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(0)); |  | ||||||
| 	else |  | ||||||
| 		ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(center_idx)); |  | ||||||
| 	center_idx = (center_idx - channel) * 5 + freq_val; |  | ||||||
| 	ucv_object_add(ret, "center_freq1", ucv_int64_new(center_idx)); |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *uc_wpa_getpid(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	return ucv_int64_new(getpid()); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *uc_wpa_sha1(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	u8 hash[SHA1_MAC_LEN]; |  | ||||||
| 	char hash_hex[2 * ARRAY_SIZE(hash) + 1]; |  | ||||||
| 	uc_value_t *val; |  | ||||||
| 	size_t *lens; |  | ||||||
| 	const u8 **args; |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	if (!nargs) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	args = alloca(nargs * sizeof(*args)); |  | ||||||
| 	lens = alloca(nargs * sizeof(*lens)); |  | ||||||
| 	for (i = 0; i < nargs; i++) { |  | ||||||
| 		val = uc_fn_arg(i); |  | ||||||
| 		if (ucv_type(val) != UC_STRING) |  | ||||||
| 			return NULL; |  | ||||||
|  |  | ||||||
| 		args[i] = ucv_string_get(val); |  | ||||||
| 		lens[i] = ucv_string_length(val); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (sha1_vector(nargs, args, lens, hash)) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	for (i = 0; i < ARRAY_SIZE(hash); i++) |  | ||||||
| 		sprintf(hash_hex + 2 * i, "%02x", hash[i]); |  | ||||||
|  |  | ||||||
| 	return ucv_string_new_length(hash_hex, 2 * ARRAY_SIZE(hash)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_vm_t *wpa_ucode_create_vm(void) |  | ||||||
| { |  | ||||||
| 	static uc_parse_config_t config = { |  | ||||||
| 		.strict_declarations = true, |  | ||||||
| 		.lstrip_blocks = true, |  | ||||||
| 		.trim_blocks = true, |  | ||||||
| 		.raw_mode = true |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	uc_search_path_init(&config.module_search_path); |  | ||||||
| 	uc_search_path_add(&config.module_search_path, HOSTAPD_UC_PATH "*.so"); |  | ||||||
| 	uc_search_path_add(&config.module_search_path, HOSTAPD_UC_PATH "*.uc"); |  | ||||||
|  |  | ||||||
| 	uc_vm_init(&vm, &config); |  | ||||||
|  |  | ||||||
| 	uc_stdlib_load(uc_vm_scope_get(&vm)); |  | ||||||
| 	eloop_add_uloop(); |  | ||||||
| 	gc_timer.cb = uc_gc_timer; |  | ||||||
|  |  | ||||||
| 	return &vm; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int wpa_ucode_run(const char *script) |  | ||||||
| { |  | ||||||
| 	uc_source_t *source; |  | ||||||
| 	uc_program_t *prog; |  | ||||||
| 	uc_value_t *ops; |  | ||||||
| 	char *err; |  | ||||||
| 	int ret; |  | ||||||
|  |  | ||||||
| 	source = uc_source_new_file(script); |  | ||||||
| 	if (!source) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	prog = uc_compile(vm.config, source, &err); |  | ||||||
| 	uc_source_put(source); |  | ||||||
| 	if (!prog) { |  | ||||||
| 		wpa_printf(MSG_ERROR, "Error loading ucode: %s\n", err); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ret = uc_vm_execute(&vm, prog, &ops); |  | ||||||
| 	uc_program_put(prog); |  | ||||||
| 	if (ret || !ops) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	registry = ucv_array_new(&vm); |  | ||||||
| 	uc_vm_registry_set(&vm, "hostap.registry", registry); |  | ||||||
| 	ucv_array_set(registry, 0, ucv_get(ops)); |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int wpa_ucode_call_prepare(const char *fname) |  | ||||||
| { |  | ||||||
| 	uc_value_t *obj, *func; |  | ||||||
|  |  | ||||||
| 	if (!registry) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	obj = ucv_array_get(registry, 0); |  | ||||||
| 	if (!obj) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	func = ucv_object_get(obj, fname, NULL); |  | ||||||
| 	if (!ucv_is_callable(func)) |  | ||||||
| 		return -1; |  | ||||||
|  |  | ||||||
| 	uc_vm_stack_push(&vm, ucv_get(obj)); |  | ||||||
| 	uc_vm_stack_push(&vm, ucv_get(func)); |  | ||||||
|  |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *wpa_ucode_global_init(const char *name, uc_resource_type_t *global_type) |  | ||||||
| { |  | ||||||
| 	uc_value_t *global = uc_resource_new(global_type, NULL); |  | ||||||
| 	uc_value_t *proto; |  | ||||||
|  |  | ||||||
| 	uc_vm_registry_set(&vm, "hostap.global", global); |  | ||||||
| 	proto = ucv_prototype_get(global); |  | ||||||
| 	ucv_object_add(proto, "data", ucv_get(ucv_object_new(&vm))); |  | ||||||
|  |  | ||||||
| #define ADD_CONST(x) ucv_object_add(proto, #x, ucv_int64_new(x)) |  | ||||||
| 	ADD_CONST(MSG_EXCESSIVE); |  | ||||||
| 	ADD_CONST(MSG_MSGDUMP); |  | ||||||
| 	ADD_CONST(MSG_DEBUG); |  | ||||||
| 	ADD_CONST(MSG_INFO); |  | ||||||
| 	ADD_CONST(MSG_WARNING); |  | ||||||
| 	ADD_CONST(MSG_ERROR); |  | ||||||
| #undef ADD_CONST |  | ||||||
|  |  | ||||||
| 	ucv_object_add(uc_vm_scope_get(&vm), name, ucv_get(global)); |  | ||||||
|  |  | ||||||
| 	return global; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int wpa_ucode_registry_add(uc_value_t *reg, uc_value_t *val) |  | ||||||
| { |  | ||||||
| 	uc_value_t *data; |  | ||||||
| 	int i = 0; |  | ||||||
|  |  | ||||||
| 	while (ucv_array_get(reg, i)) |  | ||||||
| 		i++; |  | ||||||
|  |  | ||||||
| 	ucv_array_set(reg, i, ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	return i + 1; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *wpa_ucode_registry_get(uc_value_t *reg, int idx) |  | ||||||
| { |  | ||||||
| 	if (!idx) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	return ucv_array_get(reg, idx - 1); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uc_value_t *wpa_ucode_registry_remove(uc_value_t *reg, int idx) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val = wpa_ucode_registry_get(reg, idx); |  | ||||||
| 	void **dataptr; |  | ||||||
|  |  | ||||||
| 	if (!val) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	ucv_array_set(reg, idx - 1, NULL); |  | ||||||
| 	dataptr = ucv_resource_dataptr(val, NULL); |  | ||||||
| 	if (dataptr) |  | ||||||
| 		*dataptr = NULL; |  | ||||||
|  |  | ||||||
| 	return val; |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| uc_value_t *wpa_ucode_call(size_t nargs) |  | ||||||
| { |  | ||||||
| 	if (uc_vm_call(&vm, true, nargs) != EXCEPTION_NONE) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	if (!gc_timer.pending) |  | ||||||
| 		uloop_timeout_set(&gc_timer, 10); |  | ||||||
|  |  | ||||||
| 	return uc_vm_stack_pop(&vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpa_ucode_free_vm(void) |  | ||||||
| { |  | ||||||
| 	if (!vm.config) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_search_path_free(&vm.config->module_search_path); |  | ||||||
| 	uc_vm_free(&vm); |  | ||||||
| 	registry = NULL; |  | ||||||
| 	vm = (uc_vm_t){}; |  | ||||||
| } |  | ||||||
| @@ -1,281 +0,0 @@ | |||||||
| #include "utils/includes.h" |  | ||||||
| #include "utils/common.h" |  | ||||||
| #include "utils/ucode.h" |  | ||||||
| #include "drivers/driver.h" |  | ||||||
| #include "ap/hostapd.h" |  | ||||||
| #include "wpa_supplicant_i.h" |  | ||||||
| #include "wps_supplicant.h" |  | ||||||
| #include "bss.h" |  | ||||||
| #include "ucode.h" |  | ||||||
|  |  | ||||||
| static struct wpa_global *wpa_global; |  | ||||||
| static uc_resource_type_t *global_type, *iface_type; |  | ||||||
| static uc_value_t *global, *iface_registry; |  | ||||||
| static uc_vm_t *vm; |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| wpas_ucode_iface_get_uval(struct wpa_supplicant *wpa_s) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (wpa_s->ucode.idx) |  | ||||||
| 		return wpa_ucode_registry_get(iface_registry, wpa_s->ucode.idx); |  | ||||||
|  |  | ||||||
| 	val = uc_resource_new(iface_type, wpa_s); |  | ||||||
| 	wpa_s->ucode.idx = wpa_ucode_registry_add(iface_registry, val); |  | ||||||
|  |  | ||||||
| 	return val; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void |  | ||||||
| wpas_ucode_update_interfaces(void) |  | ||||||
| { |  | ||||||
| 	uc_value_t *ifs = ucv_object_new(vm); |  | ||||||
| 	struct wpa_supplicant *wpa_s; |  | ||||||
| 	int i; |  | ||||||
|  |  | ||||||
| 	for (wpa_s = wpa_global->ifaces; wpa_s; wpa_s = wpa_s->next) |  | ||||||
| 		ucv_object_add(ifs, wpa_s->ifname, ucv_get(wpas_ucode_iface_get_uval(wpa_s))); |  | ||||||
|  |  | ||||||
| 	ucv_object_add(ucv_prototype_get(global), "interfaces", ucv_get(ifs)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpas_ucode_add_bss(struct wpa_supplicant *wpa_s) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("iface_add")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(wpa_s->ifname))); |  | ||||||
| 	uc_value_push(ucv_get(wpas_ucode_iface_get_uval(wpa_s))); |  | ||||||
| 	ucv_put(wpa_ucode_call(2)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpas_ucode_free_bss(struct wpa_supplicant *wpa_s) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_registry_remove(iface_registry, wpa_s->ucode.idx); |  | ||||||
| 	if (!val) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	wpa_s->ucode.idx = 0; |  | ||||||
| 	if (wpa_ucode_call_prepare("iface_remove")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(wpa_s->ifname))); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	ucv_put(wpa_ucode_call(2)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpas_ucode_update_state(struct wpa_supplicant *wpa_s) |  | ||||||
| { |  | ||||||
| 	const char *state; |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_registry_get(iface_registry, wpa_s->ucode.idx); |  | ||||||
| 	if (!val) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("state")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	state = wpa_supplicant_state_txt(wpa_s->wpa_state); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(wpa_s->ifname))); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(state))); |  | ||||||
| 	ucv_put(wpa_ucode_call(3)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpas_ucode_event(struct wpa_supplicant *wpa_s, int event, union wpa_event_data *data) |  | ||||||
| { |  | ||||||
| 	const char *state; |  | ||||||
| 	uc_value_t *val; |  | ||||||
|  |  | ||||||
| 	if (event != EVENT_CH_SWITCH_STARTED) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	val = wpa_ucode_registry_get(iface_registry, wpa_s->ucode.idx); |  | ||||||
| 	if (!val) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_call_prepare("event")) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(wpa_s->ifname))); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
| 	uc_value_push(ucv_get(ucv_string_new(event_to_string(event)))); |  | ||||||
| 	val = ucv_object_new(vm); |  | ||||||
| 	uc_value_push(ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	if (event == EVENT_CH_SWITCH_STARTED) { |  | ||||||
| 		ucv_object_add(val, "csa_count", ucv_int64_new(data->ch_switch.count)); |  | ||||||
| 		ucv_object_add(val, "frequency", ucv_int64_new(data->ch_switch.freq)); |  | ||||||
| 		ucv_object_add(val, "sec_chan_offset", ucv_int64_new(data->ch_switch.ch_offset)); |  | ||||||
| 		ucv_object_add(val, "center_freq1", ucv_int64_new(data->ch_switch.cf1)); |  | ||||||
| 		ucv_object_add(val, "center_freq2", ucv_int64_new(data->ch_switch.cf2)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ucv_put(wpa_ucode_call(4)); |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static const char *obj_stringval(uc_value_t *obj, const char *name) |  | ||||||
| { |  | ||||||
| 	uc_value_t *val = ucv_object_get(obj, name, NULL); |  | ||||||
|  |  | ||||||
| 	return ucv_string_get(val); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_wpas_add_iface(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	uc_value_t *info = uc_fn_arg(0); |  | ||||||
| 	uc_value_t *ifname = ucv_object_get(info, "iface", NULL); |  | ||||||
| 	uc_value_t *bridge = ucv_object_get(info, "bridge", NULL); |  | ||||||
| 	uc_value_t *config = ucv_object_get(info, "config", NULL); |  | ||||||
| 	uc_value_t *ctrl = ucv_object_get(info, "ctrl", NULL); |  | ||||||
| 	struct wpa_interface iface; |  | ||||||
| 	int ret = -1; |  | ||||||
|  |  | ||||||
| 	if (ucv_type(info) != UC_OBJECT) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	iface = (struct wpa_interface){ |  | ||||||
| 		.driver = "nl80211", |  | ||||||
| 		.ifname = ucv_string_get(ifname), |  | ||||||
| 		.bridge_ifname = ucv_string_get(bridge), |  | ||||||
| 		.confname = ucv_string_get(config), |  | ||||||
| 		.ctrl_interface = ucv_string_get(ctrl), |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	if (!iface.ifname || !iface.confname) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	ret = wpa_supplicant_add_iface(wpa_global, &iface, 0) ? 0 : -1; |  | ||||||
| 	wpas_ucode_update_interfaces(); |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	return ucv_int64_new(ret); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_wpas_remove_iface(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct wpa_supplicant *wpa_s = NULL; |  | ||||||
| 	uc_value_t *ifname_arg = uc_fn_arg(0); |  | ||||||
| 	const char *ifname = ucv_string_get(ifname_arg); |  | ||||||
| 	int ret = -1; |  | ||||||
|  |  | ||||||
| 	if (!ifname) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	for (wpa_s = wpa_global->ifaces; wpa_s; wpa_s = wpa_s->next) |  | ||||||
| 		if (!strcmp(wpa_s->ifname, ifname)) |  | ||||||
| 			break; |  | ||||||
|  |  | ||||||
| 	if (!wpa_s) |  | ||||||
| 		goto out; |  | ||||||
|  |  | ||||||
| 	ret = wpa_supplicant_remove_iface(wpa_global, wpa_s, 0); |  | ||||||
| 	wpas_ucode_update_interfaces(); |  | ||||||
|  |  | ||||||
| out: |  | ||||||
| 	return ucv_int64_new(ret); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static uc_value_t * |  | ||||||
| uc_wpas_iface_status(uc_vm_t *vm, size_t nargs) |  | ||||||
| { |  | ||||||
| 	struct wpa_supplicant *wpa_s = uc_fn_thisval("wpas.iface"); |  | ||||||
| 	struct wpa_bss *bss; |  | ||||||
| 	uc_value_t *ret, *val; |  | ||||||
|  |  | ||||||
| 	if (!wpa_s) |  | ||||||
| 		return NULL; |  | ||||||
|  |  | ||||||
| 	ret = ucv_object_new(vm); |  | ||||||
|  |  | ||||||
| 	val = ucv_string_new(wpa_supplicant_state_txt(wpa_s->wpa_state)); |  | ||||||
| 	ucv_object_add(ret, "state", ucv_get(val)); |  | ||||||
|  |  | ||||||
| 	bss = wpa_s->current_bss; |  | ||||||
| 	if (bss) { |  | ||||||
| 		int sec_chan = 0; |  | ||||||
| 		const u8 *ie; |  | ||||||
|  |  | ||||||
| 		ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION); |  | ||||||
| 		if (ie && ie[1] >= 2) { |  | ||||||
| 			const struct ieee80211_ht_operation *ht_oper; |  | ||||||
| 			int sec; |  | ||||||
|  |  | ||||||
| 			ht_oper = (const void *) (ie + 2); |  | ||||||
| 			sec = ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; |  | ||||||
| 			if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) |  | ||||||
| 				sec_chan = 1; |  | ||||||
| 			else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) |  | ||||||
| 				sec_chan = -1; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		ucv_object_add(ret, "sec_chan_offset", ucv_int64_new(sec_chan)); |  | ||||||
| 		ucv_object_add(ret, "frequency", ucv_int64_new(bss->freq)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| #ifdef CONFIG_MESH |  | ||||||
| 	if (wpa_s->ifmsh) { |  | ||||||
| 		struct hostapd_iface *ifmsh = wpa_s->ifmsh; |  | ||||||
|  |  | ||||||
| 		ucv_object_add(ret, "sec_chan_offset", ucv_int64_new(ifmsh->conf->secondary_channel)); |  | ||||||
| 		ucv_object_add(ret, "frequency", ucv_int64_new(ifmsh->freq)); |  | ||||||
| 	} |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int wpas_ucode_init(struct wpa_global *gl) |  | ||||||
| { |  | ||||||
| 	static const uc_function_list_t global_fns[] = { |  | ||||||
| 		{ "printf",	uc_wpa_printf }, |  | ||||||
| 		{ "getpid", uc_wpa_getpid }, |  | ||||||
| 		{ "add_iface", uc_wpas_add_iface }, |  | ||||||
| 		{ "remove_iface", uc_wpas_remove_iface }, |  | ||||||
| 	}; |  | ||||||
| 	static const uc_function_list_t iface_fns[] = { |  | ||||||
| 		{ "status", uc_wpas_iface_status }, |  | ||||||
| 	}; |  | ||||||
| 	uc_value_t *data, *proto; |  | ||||||
|  |  | ||||||
| 	wpa_global = gl; |  | ||||||
| 	vm = wpa_ucode_create_vm(); |  | ||||||
|  |  | ||||||
| 	global_type = uc_type_declare(vm, "wpas.global", global_fns, NULL); |  | ||||||
| 	iface_type = uc_type_declare(vm, "wpas.iface", iface_fns, NULL); |  | ||||||
|  |  | ||||||
| 	iface_registry = ucv_array_new(vm); |  | ||||||
| 	uc_vm_registry_set(vm, "wpas.iface_registry", iface_registry); |  | ||||||
|  |  | ||||||
| 	global = wpa_ucode_global_init("wpas", global_type); |  | ||||||
|  |  | ||||||
| 	if (wpa_ucode_run(HOSTAPD_UC_PATH "wpa_supplicant.uc")) |  | ||||||
| 		goto free_vm; |  | ||||||
|  |  | ||||||
| 	ucv_gc(vm); |  | ||||||
| 	return 0; |  | ||||||
|  |  | ||||||
| free_vm: |  | ||||||
| 	wpa_ucode_free_vm(); |  | ||||||
| 	return -1; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void wpas_ucode_free(void) |  | ||||||
| { |  | ||||||
| 	if (wpa_ucode_call_prepare("shutdown") == 0) |  | ||||||
| 		ucv_put(wpa_ucode_call(0)); |  | ||||||
| 	wpa_ucode_free_vm(); |  | ||||||
| } |  | ||||||
							
								
								
									
										701
									
								
								feeds/ipq40xx/ath10k-ct-firmware/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										701
									
								
								feeds/ipq40xx/ath10k-ct-firmware/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,701 @@ | |||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=ath10k-ct-firmware | ||||||
|  | PKG_VERSION:=2020-10-07 | ||||||
|  | PKG_RELEASE:=2 | ||||||
|  | CTVER1=021 | ||||||
|  | CTVER2=021 | ||||||
|  |  | ||||||
|  | # From fw_lede.bash, or can do it manually as well. | ||||||
|  | H988XFC=a4c3d1e2fb80f6b8b9738c7189795ab9505e6c09efc12ba5f08ee7f49e934239 | ||||||
|  | H988XFCH=93108bd0870652860cdb57749f5a12205ecb15bb1f129d916ad73b6f06406c82 | ||||||
|  | H9887FC=459692deb186a63ab8eeddb7ad5d54779266e68ca686e7c46062554db6dca12b | ||||||
|  | H9887FCH=fd126a457d0927d0c8ea10d66ef5b67d5e1e0741f8692bb3016bb602d0af3098 | ||||||
|  | H9980FC=52300e9d128c3d506e0b133d7a7964df3115f9511f1b574ef2a0767972c063bd | ||||||
|  | H9980FCH=9c20c3a44b701f8fef0fe02f156e382b36b717fb56c76d540f6eac2077ec189b | ||||||
|  | H9980CH=55f27045e7cf87a6a5656a050771d6d7a6197153a0737288a702c0836d5c6572 | ||||||
|  | H9980FHQ=add509b2a15ba90869f403c2e4440dbb91bd7037188d8468249cf1263adfd44e | ||||||
|  | H9984FC=e6354a1547a308b4b0fe4cbc29693848c234acedd9e7a483a1b4fb5f9bbf0dc0 | ||||||
|  | H9984FCH=6e19ecd0b001ffb594a8b033deb2007595b8c0402402789b7de55b208639ebec | ||||||
|  | H9984CH=7b6fdf3d970f3eff7c34df476c934a9bebb4f289b7968067950d31b82c71bb07 | ||||||
|  | H9984FHQ=f6a5d5a3a7b2c9267dc31673a19ee3b5312a2f84f26123cb5e8c000428ed76d2 | ||||||
|  | H4019FC=cde992cb328680e81cf85e195554699bcceef065c0c696ce4ef90c3311ab11fb | ||||||
|  | H4019FCH=818afeb1226389357dfde754d641f936fb82ebe78607f10e15efd5c952a54f48 | ||||||
|  | H4019CH=30ba10f0d82116c6617cb58c3df5cc81e5ed8f29dbc8f95c0ca9c5013ce4f702 | ||||||
|  | H4019FHQ=8e4161f7bed5bd56513ca5caab582a6eee64e9e14a69f4de67587563b7b4d735 | ||||||
|  | H9888FC=d24e66bdb2f1098a2e06ff20fe037e31937e1a483e87c68827830513b4233b5d | ||||||
|  | H9888FCH=5891e1c184da433ecc12ca0176ca89a77f7bc2b675576698b69bc93d46b77042 | ||||||
|  | H9888CH=b94f46cdda6171e5f566b1cdd6aafd68ff1a4f7e8a27762b90eb5d4f03839d99 | ||||||
|  | H9888FHQ=3cc81f8707bf5ba63bc9ffc14578c77637cae0e15766ae146af02eefb9ab7bfd | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | ATH10K_FIRMWARE_REV:=d622d160e9f552ead68d9ae81b715422892dc2ef | ||||||
|  | ATH10K_FIRMWARE_URL:=@GITHUB/kvalo/ath10k-firmware/$(ATH10K_FIRMWARE_REV) | ||||||
|  |  | ||||||
|  | QCA9887_BOARD_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca9887-board.bin | ||||||
|  | define Download/qca9887-board | ||||||
|  |   FILE:=$(QCA9887_BOARD_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA9887/hw1.0 | ||||||
|  |   URL_FILE:=board.bin | ||||||
|  |   HASH:=cf4df099f6ee05c181f55ce17297a1d32c61d725eb96246fd315ad5587c42426 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca9887-board)) | ||||||
|  |  | ||||||
|  | QCA988X_BOARD_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca988x-board.bin | ||||||
|  | define Download/qca988x-board | ||||||
|  |   FILE:=$(QCA988X_BOARD_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA988X/hw2.0 | ||||||
|  |   URL_FILE:=board.bin | ||||||
|  |   HASH:=5b5b380333c2dd3b6ce67f30e2f7008f4020bf594970d3b464fd8d4a80fcd880 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca988x-board)) | ||||||
|  |  | ||||||
|  | QCA99X0_BOARD_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca99x0-board.bin | ||||||
|  | define Download/qca99x0-board | ||||||
|  |   FILE:=$(QCA99X0_BOARD_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA99X0/hw2.0 | ||||||
|  |   URL_FILE:=boardData_AR900B_CUS239_5G_v2_001.bin | ||||||
|  |   HASH:=3bf7561ee373b369025dcd366d276d038a97d3397ccae41ce841d98a58b30aff | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca99x0-board)) | ||||||
|  |  | ||||||
|  | QCA99X0_BOARD2_REV:=ddcec9efd245da9365c474f513a855a55f3ac7fe | ||||||
|  | QCA99X0_BOARD2_FILE:=ath10k-firmware-$(QCA99X0_BOARD2_REV)-qca99x0-board-2.bin | ||||||
|  | define Download/qca99x0-board2 | ||||||
|  |   FILE:=$(QCA99X0_BOARD2_FILE) | ||||||
|  |   URL:=https://source.codeaurora.org/quic/qsdk/oss/firmware/ath10k-firmware/plain/ath10k/QCA99X0/hw2.0 | ||||||
|  |   URL_FILE:=board-2.bin?id=$(QCA99X0_BOARD2_REV) | ||||||
|  |   HASH:=03711ac21e60ef59d3815e235eb721c0c22851b5410299411085aa6f2af45401 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca99x0-board2)) | ||||||
|  |  | ||||||
|  | QCA9984_BOARD2_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca9984-board-2.bin | ||||||
|  | define Download/qca9984-board2 | ||||||
|  |   FILE:=$(QCA9984_BOARD2_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA9984/hw1.0 | ||||||
|  |   URL_FILE:=board-2.bin | ||||||
|  |   HASH:=0d6d46cf0467185e3959ce3cb69e2415be6e48ab8a4bee3eb400edbe48cb9c25 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca9984-board2)) | ||||||
|  |  | ||||||
|  | QCA4019_BOARD2_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca4019-board-2.bin | ||||||
|  | define Download/qca4019-board2 | ||||||
|  |   FILE:=$(QCA4019_BOARD2_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA4019/hw1.0 | ||||||
|  |   URL_FILE:=board-2.bin | ||||||
|  |   HASH:=94b66aa4ddbed5110a96364d3c7b4ebcb320e3ac4e8697660b277e76077bc338 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca4019-board2)) | ||||||
|  |  | ||||||
|  | QCA9888_BOARD2_FILE:=ath10k-firmware-$(ATH10K_FIRMWARE_REV)-qca9888-board-2.bin | ||||||
|  | define Download/qca9888-board2 | ||||||
|  |   FILE:=$(QCA9888_BOARD2_FILE) | ||||||
|  |   URL:=$(ATH10K_FIRMWARE_URL)/QCA9888/hw2.0 | ||||||
|  |   URL_FILE:=board-2.bin | ||||||
|  |   HASH:=5b871bb567f64525ca45adb88063211de472015d09e0f9aa3fa61ab71c8fdfd3 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca9888-board2)) | ||||||
|  |  | ||||||
|  | CT_FIRMWARE_FILE = $(1)-$($(1)_FIRMWARE_FILE_CT) | ||||||
|  | CT_FIRMWARE_FILE_FULL_HTT = $(1)-$($(1)_FIRMWARE_FILE_CT_FULL_HTT) | ||||||
|  | CT_FIRMWARE_FILE_HTT = $(1)-$($(1)_FIRMWARE_FILE_CT_HTT) | ||||||
|  |  | ||||||
|  | define Download/ct-firmware | ||||||
|  |   URL:=https://www.candelatech.com/downloads/$(2) | ||||||
|  |   FILE:=$(call CT_FIRMWARE_FILE,$(1)) | ||||||
|  |   URL_FILE:=$($(1)_FIRMWARE_FILE_CT) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Download/ct-firmware-full-htt | ||||||
|  |   URL:=https://www.candelatech.com/downloads/$(2) | ||||||
|  |   FILE:=$(call CT_FIRMWARE_FILE_FULL_HTT,$(1)) | ||||||
|  |   URL_FILE:=$($(1)_FIRMWARE_FILE_CT_FULL_HTT) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Download/ct-firmware-htt | ||||||
|  |   URL:=https://www.candelatech.com/downloads/$(2) | ||||||
|  |   FILE:=$(call CT_FIRMWARE_FILE_HTT,$(1)) | ||||||
|  |   URL_FILE:=$($(1)_FIRMWARE_FILE_CT_HTT) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | QCA988X_FIRMWARE_FILE_CT:=firmware-2-ct-full-community-22.bin.lede.$(CTVER1) | ||||||
|  | define Download/ath10k-firmware-qca988x-ct | ||||||
|  |   $(call Download/ct-firmware,QCA988X,) | ||||||
|  |   HASH:=$(H988XFC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca988x-ct)) | ||||||
|  |  | ||||||
|  | QCA988X_FIRMWARE_FILE_CT_FULL_HTT:=firmware-2-ct-full-htt-mgt-community-22.bin.lede.$(CTVER1) | ||||||
|  | define Download/ath10k-firmware-qca988x-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA988X,) | ||||||
|  |   HASH:=$(H988XFCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca988x-ct-full-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QCA9887_FIRMWARE_FILE_CT:=firmware-2-ct-full-community-22.bin.lede.$(CTVER1) | ||||||
|  | define Download/ath10k-firmware-qca9887-ct | ||||||
|  |   $(call Download/ct-firmware,QCA9887,ath10k-9887) | ||||||
|  |   HASH:=$(H9887FC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9887-ct)) | ||||||
|  |  | ||||||
|  | QCA9887_FIRMWARE_FILE_CT_FULL_HTT:=firmware-2-ct-full-htt-mgt-community-22.bin.lede.$(CTVER1) | ||||||
|  | define Download/ath10k-firmware-qca9887-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA9887,ath10k-9887) | ||||||
|  |   HASH:=$(H9887FCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9887-ct-full-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QCA99X0_FIRMWARE_FILE_CT:=firmware-5-ct-full-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca99x0-ct | ||||||
|  |   $(call Download/ct-firmware,QCA99X0,ath10k-10-4b) | ||||||
|  |   HASH:=$(H9980FC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca99x0-ct)) | ||||||
|  |  | ||||||
|  | QCA99X0_FIRMWARE_FILE_CT_FULL_HTT:=firmware-5-ct-full-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca99x0-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA99X0,ath10k-10-4b) | ||||||
|  |   HASH:=$(H9980FCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca99x0-ct-full-htt)) | ||||||
|  |  | ||||||
|  | QCA99X0_FIRMWARE_FILE_CT_HTT:=firmware-5-ct-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca99x0-ct-htt | ||||||
|  |   $(call Download/ct-firmware-htt,QCA99X0,ath10k-10-4b) | ||||||
|  |   HASH:=$(H9980CH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca99x0-ct-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QCA9984_FIRMWARE_FILE_CT:=firmware-5-ct-full-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9984-ct | ||||||
|  |   $(call Download/ct-firmware,QCA9984,ath10k-9984-10-4b) | ||||||
|  |   HASH:=$(H9984FC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9984-ct)) | ||||||
|  |  | ||||||
|  | QCA9984_FIRMWARE_FILE_CT_FULL_HTT:=firmware-5-ct-full-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9984-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA9984,ath10k-9984-10-4b) | ||||||
|  |   HASH:=$(H9984FCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9984-ct-full-htt)) | ||||||
|  |  | ||||||
|  | QCA9984_FIRMWARE_FILE_CT_HTT:=firmware-5-ct-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9984-ct-htt | ||||||
|  |   $(call Download/ct-firmware-htt,QCA9984,ath10k-9984-10-4b) | ||||||
|  |   HASH:=$(H9984CH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9984-ct-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QCA4019_FIRMWARE_FILE_CT:=firmware-5-ct-full-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca4019-ct | ||||||
|  |   $(call Download/ct-firmware,QCA4019,ath10k-4019-10-4b) | ||||||
|  |   HASH:=$(H4019FC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca4019-ct)) | ||||||
|  |  | ||||||
|  | QCA4019_FIRMWARE_FILE_CT_FULL_HTT:=firmware-5-ct-full-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca4019-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA4019,ath10k-4019-10-4b) | ||||||
|  |   HASH:=$(H4019FCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca4019-ct-full-htt)) | ||||||
|  |  | ||||||
|  | QCA4019_FIRMWARE_FILE_CT_HTT:=firmware-5-ct-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca4019-ct-htt | ||||||
|  |   $(call Download/ct-firmware-htt,QCA4019,ath10k-4019-10-4b) | ||||||
|  |   HASH:=$(H4019CH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca4019-ct-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QCA9888_FIRMWARE_FILE_CT:=firmware-5-ct-full-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9888-ct | ||||||
|  |   $(call Download/ct-firmware,QCA9888,ath10k-9888-10-4b) | ||||||
|  |   HASH:=$(H9888FC) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9888-ct)) | ||||||
|  |  | ||||||
|  | QCA9888_FIRMWARE_FILE_CT_FULL_HTT:=firmware-5-ct-full-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9888-ct-full-htt | ||||||
|  |   $(call Download/ct-firmware-full-htt,QCA9888,ath10k-9888-10-4b) | ||||||
|  |   HASH:=$(H9888FCH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9888-ct-full-htt)) | ||||||
|  |  | ||||||
|  | QCA9888_FIRMWARE_FILE_CT_HTT:=firmware-5-ct-htt-mgt-community-12.bin-lede.$(CTVER2) | ||||||
|  | define Download/ath10k-firmware-qca9888-ct-htt | ||||||
|  |   $(call Download/ct-firmware-htt,QCA9888,ath10k-9888-10-4b) | ||||||
|  |   HASH:=$(H9888CH) | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,ath10k-firmware-qca9888-ct-htt)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | define Package/ath10k-ct-firmware-default | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   URL:=https://www.candelatech.com/ath10k.php | ||||||
|  |   DEPENDS:= | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca988x-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.1 firmware for QCA988x devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca988x | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca988x-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.1 full-htt-mgt fw for QCA988x | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca988x | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9887-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.1 firmware for QCA9887 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9887 | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9887-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.1 full-htt-mgt fw for QCA9887 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9887 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 firmware for QCA99x0 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca99x0 | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 full-htt-mgt fw for QCA99x0 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca99x0 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-htt | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 htt-mgt fw for QCA99x0 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca99x0 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9984-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 firmware for QCA9984 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9984 | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 full-htt-mgt fw for QCA9984 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9984 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-htt | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 htt-mgt fw for QCA9984 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9984 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca4019-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 firmware for QCA4018/9 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca4019 | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 full-htt-mgt for QCA4018/9 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca4019 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-htt | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 htt-mgt for QCA4018/9 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca4019 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9888-ct | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 fw for QCA9886/8 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9888 | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-full-htt | ||||||
|  | $(Package/ath10k-ct-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 full-htt-mgt fw for QCA9886/8 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9888 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-htt | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k CT 10.4 htt-mgt fw for QCA9886/8 | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   PROVIDES:=ath10k-firmware-qca9888 | ||||||
|  |   DEPENDS:=+!PACKAGE_kmod-ath10k-ct-smallbuffers:kmod-ath10k-ct | ||||||
|  | endef | ||||||
|  |  | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9887-ct/description | ||||||
|  | Alternative ath10k firmware for QCA9887 from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.1.php | ||||||
|  | This firmware conflicts with the standard 9887 firmware, so select only | ||||||
|  | one. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9887-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for QCA9887 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and fixes .11r authentication. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.1.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca988x-ct/description | ||||||
|  | Alternative ath10k firmware for QCA988X from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.1.php | ||||||
|  | This firmware will NOT be used unless the standard ath10k-firmware-qca988x | ||||||
|  | is un-selected since the driver will try to load firmware-5.bin before | ||||||
|  | firmware-2.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca988x-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for QCA988X from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and fixes .11r authentication. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.1.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct/description | ||||||
|  | Alternative ath10k firmware for QCA99x0 from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware conflicts with the standard 99x0 firmware, so select only | ||||||
|  | one. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for QCA99x0 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-htt/description | ||||||
|  | Alternative ath10k firmware for QCA99x0 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | This firmware lacks a lot of features that ath10k does not use, saving | ||||||
|  | a lot of resources. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9984-ct/description | ||||||
|  | Alternative ath10k firmware for QCA9984 from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware conflicts with the standard 9984 firmware, so select only | ||||||
|  | one. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for QCA9984 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-htt/description | ||||||
|  | Alternative ath10k firmware for QCA9984 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | This firmware lacks a lot of features that ath10k does not use, saving | ||||||
|  | a lot of resources. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca4019-ct/description | ||||||
|  | Alternative ath10k firmware for IPQ4019 radio from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  Works with standard or ath10k-ct driver. | ||||||
|  | See:  http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for IPQ4019 radio from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | Enables IBSS and other features. | ||||||
|  | See:  http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-htt/description | ||||||
|  | Alternative ath10k firmware for IPQ4019 radio from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | This firmware lacks a lot of features that ath10k does not use, saving | ||||||
|  | a lot of resources. | ||||||
|  | Enables IBSS and other features. | ||||||
|  | See:  http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9888-ct/description | ||||||
|  | Alternative ath10k firmware for QCA9886 and QCA9888 from Candela Technologies. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware conflicts with the standard 9886 and 9888 firmware, so select only | ||||||
|  | one. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-full-htt/description | ||||||
|  | Alternative ath10k firmware for QCA9886 and QCA9888 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-htt/description | ||||||
|  | Alternative ath10k firmware for QCA9886 and QCA9888 from Candela Technologies. | ||||||
|  | Uses normal HTT TX data path for management frames, which improves | ||||||
|  | stability in busy networks and may be required for .11r authentication. | ||||||
|  | This firmware lacks a lot of features that ath10k does not use, saving | ||||||
|  | a lot of resources. | ||||||
|  | Enables IBSS and other features.  See: | ||||||
|  | http://www.candelatech.com/ath10k-10.4.php | ||||||
|  | This firmware selects and requires the ath10k-ct driver. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  |  | ||||||
|  | define Build/Compile | ||||||
|  |  | ||||||
|  | endef | ||||||
|  |  | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9887-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9887/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA9887) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/firmware-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9887_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/board.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9887-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9887/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA9887) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/ct-firmware-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9887_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/board.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca988x-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA988X/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA988X_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA988X) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/firmware-2.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca988x-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA988X/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA988X_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA988X) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/ct-firmware-2.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA99X0/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA99X0) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA99X0/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA99X0) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca99x0-ct-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA99X0/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_HTT,QCA99X0) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9984-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9984/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9984_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA9984) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9984/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9984_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA9984) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9984-ct-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9984/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9984_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_HTT,QCA9984) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca4019-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA4019/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA4019_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA4019) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA4019/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA4019_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA4019) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca4019-ct-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA4019/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA4019_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_HTT,QCA4019) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9888-ct/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9888/hw2.0 | ||||||
|  | 	ln -s \ | ||||||
|  | 		../../cal-pci-0000:01:00.0.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9888_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE,QCA9888) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-full-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9888/hw2.0 | ||||||
|  | 	ln -s \ | ||||||
|  | 		../../cal-pci-0000:01:00.0.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9888_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_FULL_HTT,QCA9888) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  | define Package/ath10k-firmware-qca9888-ct-htt/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9888/hw2.0 | ||||||
|  | 	ln -s \ | ||||||
|  | 		../../cal-pci-0000:01:00.0.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA9888_BOARD2_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(call CT_FIRMWARE_FILE_HTT,QCA9888) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/ct-firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  |  | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9887-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9887-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca988x-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca988x-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca99x0-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca99x0-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca99x0-ct-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9984-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9984-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9984-ct-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca4019-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca4019-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca4019-ct-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9888-ct)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9888-ct-full-htt)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9888-ct-htt)) | ||||||
							
								
								
									
										122
									
								
								feeds/ipq40xx/ath10k-ct/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								feeds/ipq40xx/ath10k-ct/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,122 @@ | |||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=ath10k-ct | ||||||
|  | PKG_RELEASE=1 | ||||||
|  |  | ||||||
|  | PKG_LICENSE:=GPLv2 | ||||||
|  | PKG_LICENSE_FILES:= | ||||||
|  |  | ||||||
|  | PKG_SOURCE_URL:=https://github.com/greearb/ath10k-ct.git | ||||||
|  | PKG_MIRROR_HASH:=37b4f00231cb0ae00f63da1c94ae53c940c76d047ce0fb081c08a35fffbfd2c0 | ||||||
|  | PKG_SOURCE_PROTO:=git | ||||||
|  | PKG_SOURCE_DATE:=2021-05-22b | ||||||
|  | PKG_SOURCE_VERSION:=54a9ac02f1139596ea4361ebbc3e444955d86cfd | ||||||
|  | #PKG_MIRROR_HASH:=97cf22a4a57381c7eb7a9b8a8b1e347e9711ce51c89db971b4ab9a35af476ece | ||||||
|  |  | ||||||
|  | # Build the 5.4 ath10k-ct driver version.  Other option is "-4.19". | ||||||
|  | # Probably this should match as closely as | ||||||
|  | # possible to whatever mac80211 backports version is being used. | ||||||
|  | CT_KVER="-5.7" | ||||||
|  |  | ||||||
|  | PKG_MAINTAINER:=Ben Greear <greearb@candelatech.com> | ||||||
|  | PKG_BUILD_PARALLEL:=1 | ||||||
|  | PKG_EXTMOD_SUBDIRS:=ath10k$(CT_KVER) | ||||||
|  |  | ||||||
|  | STAMP_CONFIGURED_DEPENDS := $(STAGING_DIR)/usr/include/mac80211-backport/backport/autoconf.h | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/kernel.mk | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | define KernelPackage/ath10k-ct | ||||||
|  |   SUBMENU:=Wireless Drivers | ||||||
|  |   TITLE:=ath10k-ct driver optimized for CT ath10k firmware | ||||||
|  |   DEPENDS:=+kmod-mac80211 +kmod-ath +@DRIVER_11N_SUPPORT +@DRIVER_11AC_SUPPORT +@DRIVER_11W_SUPPORT @PCI_SUPPORT +kmod-hwmon-core | ||||||
|  |   FILES:=\ | ||||||
|  | 	$(PKG_BUILD_DIR)/ath10k$(CT_KVER)/ath10k_pci.ko \ | ||||||
|  | 	$(PKG_BUILD_DIR)/ath10k$(CT_KVER)/ath10k_core.ko | ||||||
|  |   AUTOLOAD:=$(call AutoProbe,ath10k_pci) | ||||||
|  |   PROVIDES:=kmod-ath10k | ||||||
|  |   VARIANT:=regular | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define KernelPackage/ath10k-ct/config | ||||||
|  |  | ||||||
|  |        config ATH10K-CT_LEDS | ||||||
|  |                bool "Enable LED support" | ||||||
|  |                default y | ||||||
|  |                depends on PACKAGE_kmod-ath10k-ct || PACKAGE_kmod-ath10k-ct-smallbuffers | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define KernelPackage/ath10k-ct-smallbuffers | ||||||
|  | $(call KernelPackage/ath10k-ct) | ||||||
|  |   TITLE+= (small buffers for low-RAM devices) | ||||||
|  |   VARIANT:=smallbuffers | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | NOSTDINC_FLAGS = \ | ||||||
|  | 	-I$(PKG_BUILD_DIR) \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211-backport/uapi \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211-backport \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211/uapi \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211 \ | ||||||
|  | 	-include backport/autoconf.h \ | ||||||
|  | 	-include backport/backport.h | ||||||
|  |  | ||||||
|  | ifdef CONFIG_PACKAGE_MAC80211_MESH | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_MAC80211_MESH | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | CT_MAKEDEFS += CONFIG_ATH10K=m CONFIG_ATH10K_PCI=m CONFIG_ATH10K_CE=y | ||||||
|  |  | ||||||
|  | # This AHB logic is needed for IPQ4019 radios | ||||||
|  | CT_MAKEDEFS += CONFIG_ATH10K_AHB=m | ||||||
|  | NOSTDINC_FLAGS += -DCONFIG_ATH10K_AHB | ||||||
|  |  | ||||||
|  | NOSTDINC_FLAGS += -DSTANDALONE_CT | ||||||
|  |  | ||||||
|  | ifdef CONFIG_PACKAGE_MAC80211_DEBUGFS | ||||||
|  |   CT_MAKEDEFS += CONFIG_ATH10K_DEBUGFS=y CONFIG_MAC80211_DEBUGFS=y | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_MAC80211_DEBUGFS | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_DEBUGFS | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifdef CONFIG_PACKAGE_ATH_DEBUG | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_DEBUG | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifdef CONFIG_PACKAGE_ATH_DFS | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_DFS_CERTIFIED | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifdef CONFIG_PACKAGE_ATH_SPECTRAL | ||||||
|  |   CT_MAKEDEFS += CONFIG_ATH10K_SPECTRAL=y | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_SPECTRAL | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifeq ($(CONFIG_ATH10K-CT_LEDS),y) | ||||||
|  |   CT_MAKEDEFS += CONFIG_ATH10K_LEDS=y | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_LEDS | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifeq ($(BUILD_VARIANT),smallbuffers) | ||||||
|  |   NOSTDINC_FLAGS += -DCONFIG_ATH10K_SMALLBUFFERS | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | define Build/Configure | ||||||
|  | 	cp $(STAGING_DIR)/usr/include/mac80211/ath/*.h $(PKG_BUILD_DIR) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | ifneq ($(findstring c,$(OPENWRT_VERBOSE)),) | ||||||
|  |   CT_MAKEDEFS += V=1 | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | define Build/Compile | ||||||
|  | 	+$(MAKE) $(CT_MAKEDEFS) $(PKG_JOBS) -C "$(LINUX_DIR)" \ | ||||||
|  | 		$(KERNEL_MAKE_FLAGS) \ | ||||||
|  | 		M="$(PKG_BUILD_DIR)/ath10k$(CT_KVER)" \ | ||||||
|  | 		NOSTDINC_FLAGS="$(NOSTDINC_FLAGS)" \ | ||||||
|  | 		modules | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | $(eval $(call KernelPackage,ath10k-ct)) | ||||||
|  | $(eval $(call KernelPackage,ath10k-ct-smallbuffers)) | ||||||
| @@ -0,0 +1,37 @@ | |||||||
|  | From: Sven Eckelmann <sven@narfation.org> | ||||||
|  | Date: Tue, 26 Feb 2019 08:06:35 +0100 | ||||||
|  | Subject: ath10k-ct: apply mac80211 rates to ath10k-ct rate state | ||||||
|  |  | ||||||
|  | The rates from mac80211 have to be copied to the state of ath10k-ct or | ||||||
|  | otherwise the ath10k_check_apply_special_rates function overwrites | ||||||
|  | them again with some default values. This breaks for example the | ||||||
|  | mcast_rate set for a wifi-iface. | ||||||
|  |  | ||||||
|  | Signed-off-by: Sven Eckelmann <sven@narfation.org> | ||||||
|  |  | ||||||
|  | --- a/ath10k-5.4/mac.c | ||||||
|  | +++ b/ath10k-5.4/mac.c | ||||||
|  | @@ -6793,6 +6793,7 @@ static void ath10k_bss_info_changed(stru | ||||||
|  |  			   "mac vdev %d mcast_rate %x\n", | ||||||
|  |  			   arvif->vdev_id, rate); | ||||||
|  |   | ||||||
|  | +		arvif->mcast_rate[band] = rate; | ||||||
|  |  		vdev_param = ar->wmi.vdev_param->mcast_data_rate; | ||||||
|  |  		ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | ||||||
|  |  						vdev_param, rate); | ||||||
|  | @@ -6801,6 +6802,7 @@ static void ath10k_bss_info_changed(stru | ||||||
|  |  				    "failed to set mcast rate on vdev %i: %d\n", | ||||||
|  |  				    arvif->vdev_id,  ret); | ||||||
|  |   | ||||||
|  | +		arvif->bcast_rate[band] = rate; | ||||||
|  |  		vdev_param = ar->wmi.vdev_param->bcast_data_rate; | ||||||
|  |  		ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | ||||||
|  |  						vdev_param, rate); | ||||||
|  | @@ -6827,6 +6829,7 @@ static void ath10k_bss_info_changed(stru | ||||||
|  |  			return; | ||||||
|  |  		} | ||||||
|  |   | ||||||
|  | +		arvif->mgt_rate[def.chan->band] = hw_rate_code; | ||||||
|  |  		vdev_param = ar->wmi.vdev_param->mgmt_rate; | ||||||
|  |  		ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | ||||||
|  |  						hw_rate_code); | ||||||
| @@ -0,0 +1,598 @@ | |||||||
|  | From: Sebastian Gottschall <s.gottschall@newmedia-net.de> | ||||||
|  |  | ||||||
|  | Adds LED and GPIO Control support for 988x, 9887, 9888, 99x0, 9984 based | ||||||
|  | chipsets with on chipset connected led's using WMI Firmware API.  The LED | ||||||
|  | device will get available named as "ath10k-phyX" at sysfs and can be controlled | ||||||
|  | with various triggers.  adds also debugfs interface for gpio control. | ||||||
|  |  | ||||||
|  | This patch is specific for OpenWRt base, as is use old backported package | ||||||
|  | with old wireless source. Support for QCA9984 is removed. | ||||||
|  | Reworked to use ath10k-ct custom source | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> | ||||||
|  | Reviewed-by: Steve deRosier <derosier@cal-sierra.com> | ||||||
|  | [kvalo: major reorg and cleanup] | ||||||
|  | Signed-off-by: Kalle Valo <kvalo@codeaurora.org> | ||||||
|  | Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> | ||||||
|  | --- | ||||||
|  |  | ||||||
|  | v13: | ||||||
|  |  | ||||||
|  | * only compile tested! | ||||||
|  |  | ||||||
|  | * fix all checkpatch warnings | ||||||
|  |  | ||||||
|  | * fix commit log | ||||||
|  |  | ||||||
|  | * sizeof(struct ath10k_gpiocontrol) -> sizeof(*gpio) | ||||||
|  |  | ||||||
|  | * unsigned -> unsigned int | ||||||
|  |  | ||||||
|  | * remove GPIOLIB code, that should be added in a separate patch | ||||||
|  |  | ||||||
|  | * rename gpio.c to leds.c | ||||||
|  |  | ||||||
|  | * add leds.h | ||||||
|  |  | ||||||
|  | * rename some functions: | ||||||
|  |  | ||||||
|  |   ath10k_attach_led() -> ath10k_leds_register() | ||||||
|  |   ath10k_unregister_led() -> ath10k_leds_unregister() | ||||||
|  |   ath10k_reset_led_pin() -> ath10k_leds_start() | ||||||
|  |  | ||||||
|  | * call ath10k_leds_unregister() before ath10k_thermal_unregister() to preserve ordering | ||||||
|  |  | ||||||
|  | * call ath10k_leds_start() only from ath10k_core_start() and not from mac.c | ||||||
|  |  | ||||||
|  | * rename struct ath10k_gpiocontrol as anonymous function under struct | ||||||
|  |   ath10k::leds, no need for memory allocation | ||||||
|  |  | ||||||
|  | * merge ath10k_add_led() to ath10k_attach_led(), which is it's only caller | ||||||
|  |  | ||||||
|  | * remove #if IS_ENABLED() checks from most of places, memory savings from those were not worth it | ||||||
|  |  | ||||||
|  | * Kconfig help text improvement and move it lower in the menu, also don't enable it by default | ||||||
|  |  | ||||||
|  | * switch to set_brightness_blocking() so that the callback can sleep, | ||||||
|  |   then no need to use ath10k_wmi_cmd_send_nowait() and can take mutex | ||||||
|  |   to access ar->state | ||||||
|  |  | ||||||
|  | * don't touch ath10k_wmi_pdev_get_temperature() | ||||||
|  |  | ||||||
|  | * as QCA6174/QCA9377 are not (yet) supported don't add the command to WMI-TLV interface | ||||||
|  |  | ||||||
|  | * remove debugfs interface, that should be added in another patch | ||||||
|  |  | ||||||
|  | * cleanup includes | ||||||
|  |  | ||||||
|  |  ath10k-5.4/Kconfig   |  10 +++ | ||||||
|  |  ath10k-5.4/Makefile  |   1 + | ||||||
|  |  ath10k-5.4/core.c    |  22 +++++++ | ||||||
|  |  ath10k-5.4/core.h    |   9 ++- | ||||||
|  |  ath10k-5.4/hw.h      |   1 + | ||||||
|  |  ath10k-5.4/leds.c    | 103 ++++++++++++++++++++++++++++++ | ||||||
|  |  ath10k-5.4/leds.h    |  45 +++++++++++++ | ||||||
|  |  ath10k-5.4/mac.c     |   1 + | ||||||
|  |  ath10k-5.4/wmi-ops.h |  32 ++++++++++ | ||||||
|  |  ath10k-5.4/wmi-tlv.c |   2 + | ||||||
|  |  ath10k-5.4/wmi.c     |  54 ++++++++++++++++ | ||||||
|  |  ath10k-5.4/wmi.h     |  35 ++++++++++ | ||||||
|  |  12 files changed, 314 insertions(+), 1 deletion(-) | ||||||
|  |  create mode 100644 ath10k-5.4/leds.c | ||||||
|  |  create mode 100644 ath10k-5.4/leds.h | ||||||
|  |  | ||||||
|  | --- a/ath10k-5.4/Kconfig | ||||||
|  | +++ b/ath10k-5.4/Kconfig | ||||||
|  | @@ -66,6 +66,16 @@ config ATH10K_DEBUGFS | ||||||
|  |   | ||||||
|  |  	  If unsure, say Y to make it easier to debug problems. | ||||||
|  |   | ||||||
|  | +config ATH10K_LEDS | ||||||
|  | +	bool "Atheros ath10k LED support" | ||||||
|  | +	depends on ATH10K | ||||||
|  | +	select MAC80211_LEDS | ||||||
|  | +	select LEDS_CLASS | ||||||
|  | +	select NEW_LEDS | ||||||
|  | +	default y | ||||||
|  | +	---help--- | ||||||
|  | +	  This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N. | ||||||
|  | + | ||||||
|  |  config ATH10K_SPECTRAL | ||||||
|  |  	bool "Atheros ath10k spectral scan support" | ||||||
|  |  	depends on ATH10K_DEBUGFS | ||||||
|  | --- a/ath10k-5.4/Makefile | ||||||
|  | +++ b/ath10k-5.4/Makefile | ||||||
|  | @@ -19,6 +19,7 @@ ath10k_core-$(CONFIG_ATH10K_SPECTRAL) += | ||||||
|  |  ath10k_core-$(CONFIG_NL80211_TESTMODE) += testmode.o | ||||||
|  |  ath10k_core-$(CONFIG_ATH10K_TRACING) += trace.o | ||||||
|  |  ath10k_core-$(CONFIG_THERMAL) += thermal.o | ||||||
|  | +ath10k_core-$(CONFIG_ATH10K_LEDS) += leds.o | ||||||
|  |  ath10k_core-$(CONFIG_MAC80211_DEBUGFS) += debugfs_sta.o | ||||||
|  |  ath10k_core-$(CONFIG_PM) += wow.o | ||||||
|  |  ath10k_core-$(CONFIG_DEV_COREDUMP) += coredump.o | ||||||
|  | --- a/ath10k-5.4/core.c | ||||||
|  | +++ b/ath10k-5.4/core.c | ||||||
|  | @@ -25,6 +25,7 @@ | ||||||
|  |  #include "testmode.h" | ||||||
|  |  #include "wmi-ops.h" | ||||||
|  |  #include "coredump.h" | ||||||
|  | +#include "leds.h" | ||||||
|  |   | ||||||
|  |  /* Disable ath10k-ct DBGLOG output by default */ | ||||||
|  |  unsigned int ath10k_debug_mask = ATH10K_DBG_NO_DBGLOG; | ||||||
|  | @@ -67,6 +68,7 @@ static const struct ath10k_hw_params ath | ||||||
|  |  		.dev_id = QCA988X_2_0_DEVICE_ID, | ||||||
|  |  		.bus = ATH10K_BUS_PCI, | ||||||
|  |  		.name = "qca988x hw2.0", | ||||||
|  | +		.led_pin = 1, | ||||||
|  |  		.patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR, | ||||||
|  |  		.uart_pin = 7, | ||||||
|  |  		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL, | ||||||
|  | @@ -137,6 +139,7 @@ static const struct ath10k_hw_params ath | ||||||
|  |  		.dev_id = QCA9887_1_0_DEVICE_ID, | ||||||
|  |  		.bus = ATH10K_BUS_PCI, | ||||||
|  |  		.name = "qca9887 hw1.0", | ||||||
|  | +		.led_pin = 1, | ||||||
|  |  		.patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR, | ||||||
|  |  		.uart_pin = 7, | ||||||
|  |  		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL, | ||||||
|  | @@ -344,6 +347,7 @@ static const struct ath10k_hw_params ath | ||||||
|  |  		.dev_id = QCA99X0_2_0_DEVICE_ID, | ||||||
|  |  		.bus = ATH10K_BUS_PCI, | ||||||
|  |  		.name = "qca99x0 hw2.0", | ||||||
|  | +		.led_pin = 17, | ||||||
|  |  		.patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR, | ||||||
|  |  		.uart_pin = 7, | ||||||
|  |  		.otp_exe_param = 0x00000700, | ||||||
|  | @@ -385,6 +389,7 @@ static const struct ath10k_hw_params ath | ||||||
|  |  		.dev_id = QCA9984_1_0_DEVICE_ID, | ||||||
|  |  		.bus = ATH10K_BUS_PCI, | ||||||
|  |  		.name = "qca9984/qca9994 hw1.0", | ||||||
|  | +		.led_pin = 17, | ||||||
|  |  		.patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR, | ||||||
|  |  		.uart_pin = 7, | ||||||
|  |  		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH, | ||||||
|  | @@ -433,6 +438,7 @@ static const struct ath10k_hw_params ath | ||||||
|  |  		.dev_id = QCA9888_2_0_DEVICE_ID, | ||||||
|  |  		.bus = ATH10K_BUS_PCI, | ||||||
|  |  		.name = "qca9888 hw2.0", | ||||||
|  | +		.led_pin = 17, | ||||||
|  |  		.patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR, | ||||||
|  |  		.uart_pin = 7, | ||||||
|  |  		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH, | ||||||
|  | @@ -3573,6 +3579,10 @@ int ath10k_core_start(struct ath10k *ar, | ||||||
|  |  			ath10k_wmi_check_apply_board_power_ctl_table(ar); | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | +	status = ath10k_leds_start(ar); | ||||||
|  | +	if (status) | ||||||
|  | +		goto err_hif_stop; | ||||||
|  | + | ||||||
|  |  	return 0; | ||||||
|  |   | ||||||
|  |  err_hif_stop: | ||||||
|  | @@ -3829,9 +3839,18 @@ static void ath10k_core_register_work(st | ||||||
|  |  		goto err_spectral_destroy; | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | +	status = ath10k_leds_register(ar); | ||||||
|  | +	if (status) { | ||||||
|  | +		ath10k_err(ar, "could not register leds: %d\n", | ||||||
|  | +			   status); | ||||||
|  | +		goto err_thermal_unregister; | ||||||
|  | +	} | ||||||
|  | + | ||||||
|  |  	set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags); | ||||||
|  |  	return; | ||||||
|  |   | ||||||
|  | +err_thermal_unregister: | ||||||
|  | +	ath10k_thermal_unregister(ar); | ||||||
|  |  err_spectral_destroy: | ||||||
|  |  	ath10k_spectral_destroy(ar); | ||||||
|  |  err_debug_destroy: | ||||||
|  | @@ -3891,6 +3910,8 @@ void ath10k_core_unregister(struct ath10 | ||||||
|  |  	if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags)) | ||||||
|  |  		return; | ||||||
|  |   | ||||||
|  | +	ath10k_leds_unregister(ar); | ||||||
|  | + | ||||||
|  |  	ath10k_thermal_unregister(ar); | ||||||
|  |  	/* Stop spectral before unregistering from mac80211 to remove the | ||||||
|  |  	 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree | ||||||
|  | --- a/ath10k-5.4/core.h | ||||||
|  | +++ b/ath10k-5.4/core.h | ||||||
|  | @@ -14,6 +14,7 @@ | ||||||
|  |  #include <linux/pci.h> | ||||||
|  |  #include <linux/uuid.h> | ||||||
|  |  #include <linux/time.h> | ||||||
|  | +#include <linux/leds.h> | ||||||
|  |   | ||||||
|  |  #include "htt.h" | ||||||
|  |  #include "htc.h" | ||||||
|  | @@ -1469,6 +1470,13 @@ struct ath10k { | ||||||
|  |  	} testmode; | ||||||
|  |   | ||||||
|  |  	struct { | ||||||
|  | +		struct gpio_led wifi_led; | ||||||
|  | +		struct led_classdev cdev; | ||||||
|  | +		char label[48]; | ||||||
|  | +		u32 gpio_state_pin; | ||||||
|  | +	} leds; | ||||||
|  | + | ||||||
|  | +	struct { | ||||||
|  |  		/* protected by data_lock */ | ||||||
|  |  		u32 fw_crash_counter; | ||||||
|  |  		u32 fw_warm_reset_counter; | ||||||
|  | --- a/ath10k-5.4/hw.h | ||||||
|  | +++ b/ath10k-5.4/hw.h | ||||||
|  | @@ -518,6 +518,7 @@ struct ath10k_hw_params { | ||||||
|  |  	const char *name; | ||||||
|  |  	u32 patch_load_addr; | ||||||
|  |  	int uart_pin; | ||||||
|  | +	int led_pin; | ||||||
|  |  	u32 otp_exe_param; | ||||||
|  |   | ||||||
|  |  	/* Type of hw cycle counter wraparound logic, for more info | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/ath10k-5.4/leds.c | ||||||
|  | @@ -0,0 +1,103 @@ | ||||||
|  | +/* | ||||||
|  | + * Copyright (c) 2005-2011 Atheros Communications Inc. | ||||||
|  | + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc. | ||||||
|  | + * Copyright (c) 2018 Sebastian Gottschall <s.gottschall@dd-wrt.com> | ||||||
|  | + * Copyright (c) 2018, The Linux Foundation. All rights reserved. | ||||||
|  | + * | ||||||
|  | + * Permission to use, copy, modify, and/or distribute this software for any | ||||||
|  | + * purpose with or without fee is hereby granted, provided that the above | ||||||
|  | + * copyright notice and this permission notice appear in all copies. | ||||||
|  | + * | ||||||
|  | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||||
|  | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||||
|  | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||||
|  | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||||
|  | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||||
|  | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||||
|  | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <linux/leds.h> | ||||||
|  | + | ||||||
|  | +#include "core.h" | ||||||
|  | +#include "wmi.h" | ||||||
|  | +#include "wmi-ops.h" | ||||||
|  | + | ||||||
|  | +#include "leds.h" | ||||||
|  | + | ||||||
|  | +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev, | ||||||
|  | +					       enum led_brightness brightness) | ||||||
|  | +{ | ||||||
|  | +	struct ath10k *ar = container_of(led_cdev, struct ath10k, | ||||||
|  | +					 leds.cdev); | ||||||
|  | +	struct gpio_led *led = &ar->leds.wifi_led; | ||||||
|  | + | ||||||
|  | +	mutex_lock(&ar->conf_mutex); | ||||||
|  | + | ||||||
|  | +	if (ar->state != ATH10K_STATE_ON) | ||||||
|  | +		goto out; | ||||||
|  | + | ||||||
|  | +	ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low; | ||||||
|  | +	ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin); | ||||||
|  | + | ||||||
|  | +out: | ||||||
|  | +	mutex_unlock(&ar->conf_mutex); | ||||||
|  | + | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +int ath10k_leds_start(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +	if (ar->hw_params.led_pin == 0) | ||||||
|  | +		/* leds not supported */ | ||||||
|  | +		return 0; | ||||||
|  | + | ||||||
|  | +	/* under some circumstances, the gpio pin gets reconfigured | ||||||
|  | +	 * to default state by the firmware, so we need to | ||||||
|  | +	 * reconfigure it this behaviour has only ben seen on | ||||||
|  | +	 * QCA9984 and QCA99XX devices so far | ||||||
|  | +	 */ | ||||||
|  | +	ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0, | ||||||
|  | +			       WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE); | ||||||
|  | +	ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1); | ||||||
|  | + | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +int ath10k_leds_register(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +	int ret; | ||||||
|  | + | ||||||
|  | +	if (ar->hw_params.led_pin == 0) | ||||||
|  | +		/* leds not supported */ | ||||||
|  | +		return 0; | ||||||
|  | + | ||||||
|  | +	snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s", | ||||||
|  | +		 wiphy_name(ar->hw->wiphy)); | ||||||
|  | +	ar->leds.wifi_led.active_low = 1; | ||||||
|  | +	ar->leds.wifi_led.gpio = ar->hw_params.led_pin; | ||||||
|  | +	ar->leds.wifi_led.name = ar->leds.label; | ||||||
|  | +	ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP; | ||||||
|  | + | ||||||
|  | +	ar->leds.cdev.name = ar->leds.label; | ||||||
|  | +	ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking; | ||||||
|  | + | ||||||
|  | +	/* FIXME: this assignment doesn't make sense as it's NULL, remove it? */ | ||||||
|  | +	ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger; | ||||||
|  | + | ||||||
|  | +	ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev); | ||||||
|  | +	if (ret) | ||||||
|  | +		return ret; | ||||||
|  | + | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +void ath10k_leds_unregister(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +	if (ar->hw_params.led_pin == 0) | ||||||
|  | +		/* leds not supported */ | ||||||
|  | +		return; | ||||||
|  | + | ||||||
|  | +	led_classdev_unregister(&ar->leds.cdev); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/ath10k-5.4/leds.h | ||||||
|  | @@ -0,0 +1,41 @@ | ||||||
|  | +/* | ||||||
|  | + * Copyright (c) 2018, The Linux Foundation. All rights reserved. | ||||||
|  | + * | ||||||
|  | + * Permission to use, copy, modify, and/or distribute this software for any | ||||||
|  | + * purpose with or without fee is hereby granted, provided that the above | ||||||
|  | + * copyright notice and this permission notice appear in all copies. | ||||||
|  | + * | ||||||
|  | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||||
|  | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||||
|  | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||||
|  | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||||
|  | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||||
|  | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||||
|  | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||
|  | + */ | ||||||
|  | +#ifndef _LEDS_H_ | ||||||
|  | +#define _LEDS_H_ | ||||||
|  | + | ||||||
|  | +#include "core.h" | ||||||
|  | + | ||||||
|  | +#ifdef CONFIG_ATH10K_LEDS | ||||||
|  | +void ath10k_leds_unregister(struct ath10k *ar); | ||||||
|  | +int ath10k_leds_start(struct ath10k *ar); | ||||||
|  | +int ath10k_leds_register(struct ath10k *ar); | ||||||
|  | +#else | ||||||
|  | +static inline void ath10k_leds_unregister(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline int ath10k_leds_start(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline int ath10k_leds_register(struct ath10k *ar) | ||||||
|  | +{ | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +#endif | ||||||
|  | +#endif /* _LEDS_H_ */ | ||||||
|  | --- a/ath10k-5.4/mac.c | ||||||
|  | +++ b/ath10k-5.4/mac.c | ||||||
|  | @@ -24,6 +24,7 @@ | ||||||
|  |  #include "wmi-tlv.h" | ||||||
|  |  #include "wmi-ops.h" | ||||||
|  |  #include "wow.h" | ||||||
|  | +#include "leds.h" | ||||||
|  |   | ||||||
|  |  /*********/ | ||||||
|  |  /* Rates */ | ||||||
|  | --- a/ath10k-5.4/wmi-ops.h | ||||||
|  | +++ b/ath10k-5.4/wmi-ops.h | ||||||
|  | @@ -218,7 +218,10 @@ struct wmi_ops { | ||||||
|  |  	struct sk_buff *(*gen_bb_timing) | ||||||
|  |  			(struct ath10k *ar, | ||||||
|  |  			 const struct wmi_bb_timing_cfg_arg *arg); | ||||||
|  | +	struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num, | ||||||
|  | +					   u32 input, u32 pull_type, u32 intr_mode); | ||||||
|  |   | ||||||
|  | +	struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set); | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  |  int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id); | ||||||
|  | @@ -1105,6 +1108,35 @@ ath10k_wmi_force_fw_hang(struct ath10k * | ||||||
|  |  	return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num, | ||||||
|  | +					 u32 input, u32 pull_type, u32 intr_mode) | ||||||
|  | +{ | ||||||
|  | +	struct sk_buff *skb; | ||||||
|  | + | ||||||
|  | +	if (!ar->wmi.ops->gen_gpio_config) | ||||||
|  | +		return -EOPNOTSUPP; | ||||||
|  | + | ||||||
|  | +	skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode); | ||||||
|  | +	if (IS_ERR(skb)) | ||||||
|  | +		return PTR_ERR(skb); | ||||||
|  | + | ||||||
|  | +	return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set) | ||||||
|  | +{ | ||||||
|  | +	struct sk_buff *skb; | ||||||
|  | + | ||||||
|  | +	if (!ar->wmi.ops->gen_gpio_config) | ||||||
|  | +		return -EOPNOTSUPP; | ||||||
|  | + | ||||||
|  | +	skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set); | ||||||
|  | +	if (IS_ERR(skb)) | ||||||
|  | +		return PTR_ERR(skb); | ||||||
|  | + | ||||||
|  | +	return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  |  static inline int | ||||||
|  |  ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level) | ||||||
|  |  { | ||||||
|  | --- a/ath10k-5.4/wmi-tlv.c | ||||||
|  | +++ b/ath10k-5.4/wmi-tlv.c | ||||||
|  | @@ -4364,6 +4364,8 @@ static const struct wmi_ops wmi_tlv_ops | ||||||
|  |  	.gen_echo = ath10k_wmi_tlv_op_gen_echo, | ||||||
|  |  	.gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf, | ||||||
|  |  	.gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable, | ||||||
|  | +	/* .gen_gpio_config not implemented */ | ||||||
|  | +	/* .gen_gpio_output not implemented */ | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  |  static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = { | ||||||
|  | --- a/ath10k-5.4/wmi.c | ||||||
|  | +++ b/ath10k-5.4/wmi.c | ||||||
|  | @@ -8295,6 +8295,49 @@ ath10k_wmi_op_gen_peer_set_param(struct | ||||||
|  |  	return skb; | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar, | ||||||
|  | +						     u32 gpio_num, u32 input, | ||||||
|  | +						     u32 pull_type, u32 intr_mode) | ||||||
|  | +{ | ||||||
|  | +	struct wmi_gpio_config_cmd *cmd; | ||||||
|  | +	struct sk_buff *skb; | ||||||
|  | + | ||||||
|  | +	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd)); | ||||||
|  | +	if (!skb) | ||||||
|  | +		return ERR_PTR(-ENOMEM); | ||||||
|  | + | ||||||
|  | +	cmd = (struct wmi_gpio_config_cmd *)skb->data; | ||||||
|  | +	cmd->pull_type = __cpu_to_le32(pull_type); | ||||||
|  | +	cmd->gpio_num = __cpu_to_le32(gpio_num); | ||||||
|  | +	cmd->input = __cpu_to_le32(input); | ||||||
|  | +	cmd->intr_mode = __cpu_to_le32(intr_mode); | ||||||
|  | + | ||||||
|  | +	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_config gpio_num 0x%08x input 0x%08x pull_type 0x%08x intr_mode 0x%08x\n", | ||||||
|  | +		   gpio_num, input, pull_type, intr_mode); | ||||||
|  | + | ||||||
|  | +	return skb; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar, | ||||||
|  | +						     u32 gpio_num, u32 set) | ||||||
|  | +{ | ||||||
|  | +	struct wmi_gpio_output_cmd *cmd; | ||||||
|  | +	struct sk_buff *skb; | ||||||
|  | + | ||||||
|  | +	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd)); | ||||||
|  | +	if (!skb) | ||||||
|  | +		return ERR_PTR(-ENOMEM); | ||||||
|  | + | ||||||
|  | +	cmd = (struct wmi_gpio_output_cmd *)skb->data; | ||||||
|  | +	cmd->gpio_num = __cpu_to_le32(gpio_num); | ||||||
|  | +	cmd->set = __cpu_to_le32(set); | ||||||
|  | + | ||||||
|  | +	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n", | ||||||
|  | +		   gpio_num, set); | ||||||
|  | + | ||||||
|  | +	return skb; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  |  static struct sk_buff * | ||||||
|  |  ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id, | ||||||
|  |  			     enum wmi_sta_ps_mode psmode) | ||||||
|  | @@ -10094,6 +10137,9 @@ static const struct wmi_ops wmi_ops = { | ||||||
|  |  	.fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill, | ||||||
|  |  	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype, | ||||||
|  |  	.gen_echo = ath10k_wmi_op_gen_echo, | ||||||
|  | +	.gen_gpio_config = ath10k_wmi_op_gen_gpio_config, | ||||||
|  | +	.gen_gpio_output = ath10k_wmi_op_gen_gpio_output, | ||||||
|  | + | ||||||
|  |  	/* .gen_bcn_tmpl not implemented */ | ||||||
|  |  	/* .gen_prb_tmpl not implemented */ | ||||||
|  |  	/* .gen_p2p_go_bcn_ie not implemented */ | ||||||
|  | @@ -10164,6 +10210,8 @@ static const struct wmi_ops wmi_10_1_ops | ||||||
|  |  	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill, | ||||||
|  |  	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype, | ||||||
|  |  	.gen_echo = ath10k_wmi_op_gen_echo, | ||||||
|  | +	.gen_gpio_config = ath10k_wmi_op_gen_gpio_config, | ||||||
|  | +	.gen_gpio_output = ath10k_wmi_op_gen_gpio_output, | ||||||
|  |  	/* .gen_bcn_tmpl not implemented */ | ||||||
|  |  	/* .gen_prb_tmpl not implemented */ | ||||||
|  |  	/* .gen_p2p_go_bcn_ie not implemented */ | ||||||
|  | @@ -10243,6 +10291,8 @@ static const struct wmi_ops wmi_10_2_ops | ||||||
|  |  	.gen_delba_send = ath10k_wmi_op_gen_delba_send, | ||||||
|  |  	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill, | ||||||
|  |  	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype, | ||||||
|  | +	.gen_gpio_config = ath10k_wmi_op_gen_gpio_config, | ||||||
|  | +	.gen_gpio_output = ath10k_wmi_op_gen_gpio_output, | ||||||
|  |  	/* .gen_pdev_enable_adaptive_cca not implemented */ | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  | @@ -10314,6 +10364,8 @@ static const struct wmi_ops wmi_10_2_4_o | ||||||
|  |  		ath10k_wmi_op_gen_pdev_enable_adaptive_cca, | ||||||
|  |  	.get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype, | ||||||
|  |  	.gen_bb_timing = ath10k_wmi_10_2_4_op_gen_bb_timing, | ||||||
|  | +	.gen_gpio_config = ath10k_wmi_op_gen_gpio_config, | ||||||
|  | +	.gen_gpio_output = ath10k_wmi_op_gen_gpio_output, | ||||||
|  |  	/* .gen_bcn_tmpl not implemented */ | ||||||
|  |  	/* .gen_prb_tmpl not implemented */ | ||||||
|  |  	/* .gen_p2p_go_bcn_ie not implemented */ | ||||||
|  | @@ -10395,6 +10447,8 @@ static const struct wmi_ops wmi_10_4_ops | ||||||
|  |  	.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info, | ||||||
|  |  	.gen_echo = ath10k_wmi_op_gen_echo, | ||||||
|  |  	.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config, | ||||||
|  | +	.gen_gpio_config = ath10k_wmi_op_gen_gpio_config, | ||||||
|  | +	.gen_gpio_output = ath10k_wmi_op_gen_gpio_output, | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  |  int ath10k_wmi_attach(struct ath10k *ar) | ||||||
|  | --- a/ath10k-5.4/wmi.h | ||||||
|  | +++ b/ath10k-5.4/wmi.h | ||||||
|  | @@ -3110,6 +3110,41 @@ enum wmi_10_4_feature_mask { | ||||||
|  |   | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  | +/* WMI_GPIO_CONFIG_CMDID */ | ||||||
|  | +enum { | ||||||
|  | +	WMI_GPIO_PULL_NONE, | ||||||
|  | +	WMI_GPIO_PULL_UP, | ||||||
|  | +	WMI_GPIO_PULL_DOWN, | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +enum { | ||||||
|  | +	WMI_GPIO_INTTYPE_DISABLE, | ||||||
|  | +	WMI_GPIO_INTTYPE_RISING_EDGE, | ||||||
|  | +	WMI_GPIO_INTTYPE_FALLING_EDGE, | ||||||
|  | +	WMI_GPIO_INTTYPE_BOTH_EDGE, | ||||||
|  | +	WMI_GPIO_INTTYPE_LEVEL_LOW, | ||||||
|  | +	WMI_GPIO_INTTYPE_LEVEL_HIGH | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +/* WMI_GPIO_CONFIG_CMDID */ | ||||||
|  | +struct wmi_gpio_config_cmd { | ||||||
|  | +	__le32 gpio_num;             /* GPIO number to be setup */ | ||||||
|  | +	__le32 input;                /* 0 - Output/ 1 - Input */ | ||||||
|  | +	__le32 pull_type;            /* Pull type defined above */ | ||||||
|  | +	__le32 intr_mode;            /* Interrupt mode defined above (Input) */ | ||||||
|  | +} __packed; | ||||||
|  | + | ||||||
|  | +/* WMI_GPIO_OUTPUT_CMDID */ | ||||||
|  | +struct wmi_gpio_output_cmd { | ||||||
|  | +	__le32 gpio_num;    /* GPIO number to be setup */ | ||||||
|  | +	__le32 set;         /* Set the GPIO pin*/ | ||||||
|  | +} __packed; | ||||||
|  | + | ||||||
|  | +/* WMI_GPIO_INPUT_EVENTID */ | ||||||
|  | +struct wmi_gpio_input_event { | ||||||
|  | +	__le32 gpio_num;    /* GPIO number which changed state */ | ||||||
|  | +} __packed; | ||||||
|  | + | ||||||
|  |  struct wmi_ext_resource_config_10_4_cmd { | ||||||
|  |  	/* contains enum wmi_host_platform_type */ | ||||||
|  |  	__le32 host_platform_config; | ||||||
| @@ -0,0 +1,53 @@ | |||||||
|  | From 79c9d7aabae1d1da9eea97d83b61e1517a8a2221 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Mathias Kresin <dev@kresin.me> | ||||||
|  | Date: Fri, 22 Jun 2018 18:59:44 +0200 | ||||||
|  | Subject: [PATCH] ath10k: use tpt LED trigger by default | ||||||
|  |  | ||||||
|  | Use the tpt LED trigger for each created phy led. Ths way LEDs attached | ||||||
|  | to the ath10k GPIO pins are indicating the phy status and blink on | ||||||
|  | traffic. | ||||||
|  |  | ||||||
|  | Signed-off-by: Mathias Kresin <dev@kresin.me> | ||||||
|  | --- | ||||||
|  |  ath10k-5.4/core.h | 4 ++++ | ||||||
|  |  ath10k-5.4/leds.c | 4 +--- | ||||||
|  |  ath10k-5.4/mac.c  | 2 +- | ||||||
|  |  3 files changed, 6 insertions(+), 4 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/ath10k-5.4/core.h | ||||||
|  | +++ b/ath10k-5.4/core.h | ||||||
|  | @@ -1573,6 +1573,10 @@ struct ath10k { | ||||||
|  |  	u8 csi_data[4096]; | ||||||
|  |  	u16 csi_data_len; | ||||||
|  |   | ||||||
|  | +#ifdef CPTCFG_MAC80211_LEDS | ||||||
|  | +	const char *led_default_trigger; | ||||||
|  | +#endif | ||||||
|  | + | ||||||
|  |  	/* must be last */ | ||||||
|  |  	u8 drv_priv[0] __aligned(sizeof(void *)); | ||||||
|  |  }; | ||||||
|  | --- a/ath10k-5.4/leds.c | ||||||
|  | +++ b/ath10k-5.4/leds.c | ||||||
|  | @@ -81,9 +81,7 @@ int ath10k_leds_register(struct ath10k * | ||||||
|  |   | ||||||
|  |  	ar->leds.cdev.name = ar->leds.label; | ||||||
|  |  	ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking; | ||||||
|  | - | ||||||
|  | -	/* FIXME: this assignment doesn't make sense as it's NULL, remove it? */ | ||||||
|  | -	ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger; | ||||||
|  | +	ar->leds.cdev.default_trigger = ar->led_default_trigger; | ||||||
|  |   | ||||||
|  |  	ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev); | ||||||
|  |  	if (ret) | ||||||
|  | --- a/ath10k-5.4/mac.c | ||||||
|  | +++ b/ath10k-5.4/mac.c | ||||||
|  | @@ -10367,7 +10367,7 @@ int ath10k_mac_register(struct ath10k *a | ||||||
|  |  	ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER; | ||||||
|  |   | ||||||
|  |  #ifdef CPTCFG_MAC80211_LEDS | ||||||
|  | -	ieee80211_create_tpt_led_trigger(ar->hw, | ||||||
|  | +	ar->led_default_trigger = ieee80211_create_tpt_led_trigger(ar->hw, | ||||||
|  |  		IEEE80211_TPT_LEDTRIG_FL_RADIO, ath10k_tpt_blink, | ||||||
|  |  		ARRAY_SIZE(ath10k_tpt_blink)); | ||||||
|  |  #endif | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | --- a/ath10k-5.4/mac.c | ||||||
|  | +++ b/ath10k-5.4/mac.c | ||||||
|  | @@ -10180,6 +10180,7 @@ int ath10k_mac_register(struct ath10k *a | ||||||
|  |  	wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); | ||||||
|  |  	wiphy_ext_feature_set(ar->hw->wiphy, | ||||||
|  |  			      NL80211_EXT_FEATURE_SET_SCAN_DWELL); | ||||||
|  | +	wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_AQL); | ||||||
|  |   | ||||||
|  |  	if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) || | ||||||
|  |  	    test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map)) | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | --- a/ath10k-5.4/htt.h | ||||||
|  | +++ b/ath10k-5.4/htt.h | ||||||
|  | @@ -225,7 +225,11 @@ enum htt_rx_ring_flags { | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  |  #define HTT_RX_RING_SIZE_MIN 128 | ||||||
|  | +#ifndef CONFIG_ATH10K_SMALLBUFFERS | ||||||
|  |  #define HTT_RX_RING_SIZE_MAX 2048 | ||||||
|  | +#else | ||||||
|  | +#define HTT_RX_RING_SIZE_MAX 512 | ||||||
|  | +#endif | ||||||
|  |  #define HTT_RX_RING_SIZE HTT_RX_RING_SIZE_MAX | ||||||
|  |  #define HTT_RX_RING_FILL_LEVEL (((HTT_RX_RING_SIZE) / 2) - 1) | ||||||
|  |  #define HTT_RX_RING_FILL_LEVEL_DUAL_MAC (HTT_RX_RING_SIZE - 1) | ||||||
| @@ -0,0 +1,50 @@ | |||||||
|  | --- a/ath10k-5.4/pci.c | ||||||
|  | +++ b/ath10k-5.4/pci.c | ||||||
|  | @@ -131,7 +131,11 @@ static struct ce_attr host_ce_config_wla | ||||||
|  |  		.flags = CE_ATTR_FLAGS, | ||||||
|  |  		.src_nentries = 0, | ||||||
|  |  		.src_sz_max = 2048, | ||||||
|  | +#ifndef CONFIG_ATH10K_SMALLBUFFERS | ||||||
|  |  		.dest_nentries = 512, | ||||||
|  | +#else | ||||||
|  | +		.dest_nentries = 128, | ||||||
|  | +#endif | ||||||
|  |  		.recv_cb = ath10k_pci_htt_htc_rx_cb, | ||||||
|  |  	}, | ||||||
|  |   | ||||||
|  | @@ -140,7 +144,11 @@ static struct ce_attr host_ce_config_wla | ||||||
|  |  		.flags = CE_ATTR_FLAGS, | ||||||
|  |  		.src_nentries = 0, | ||||||
|  |  		.src_sz_max = 2048, | ||||||
|  | +#ifndef CONFIG_ATH10K_SMALLBUFFERS | ||||||
|  |  		.dest_nentries = 128, | ||||||
|  | +#else | ||||||
|  | +		.dest_nentries = 64, | ||||||
|  | +#endif | ||||||
|  |  		.recv_cb = ath10k_pci_htc_rx_cb, | ||||||
|  |  	}, | ||||||
|  |   | ||||||
|  | @@ -167,7 +175,11 @@ static struct ce_attr host_ce_config_wla | ||||||
|  |  		.flags = CE_ATTR_FLAGS, | ||||||
|  |  		.src_nentries = 0, | ||||||
|  |  		.src_sz_max = 512, | ||||||
|  | +#ifndef CONFIG_ATH10K_SMALLBUFFERS | ||||||
|  |  		.dest_nentries = 512, | ||||||
|  | +#else | ||||||
|  | +		.dest_nentries = 128, | ||||||
|  | +#endif | ||||||
|  |  		.recv_cb = ath10k_pci_htt_rx_cb, | ||||||
|  |  	}, | ||||||
|  |   | ||||||
|  | @@ -192,7 +204,11 @@ static struct ce_attr host_ce_config_wla | ||||||
|  |  		.flags = CE_ATTR_FLAGS, | ||||||
|  |  		.src_nentries = 0, | ||||||
|  |  		.src_sz_max = 2048, | ||||||
|  | +#ifndef CONFIG_ATH10K_SMALLBUFFERS | ||||||
|  |  		.dest_nentries = 128, | ||||||
|  | +#else | ||||||
|  | +		.dest_nentries = 96, | ||||||
|  | +#endif | ||||||
|  |  		.recv_cb = ath10k_pci_pktlog_rx_cb, | ||||||
|  |  	}, | ||||||
|  |   | ||||||
| @@ -0,0 +1,22 @@ | |||||||
|  | diff -Naur a/ath10k-5.7/mac.c b/ath10k-5.7/mac.c | ||||||
|  | --- a/ath10k-5.7/mac.c	2021-06-09 16:30:17.793556032 -0400 | ||||||
|  | +++ b/ath10k-5.7/mac.c	2021-06-09 17:38:08.587733979 -0400 | ||||||
|  | @@ -7103,13 +7103,15 @@ | ||||||
|  |  		scan_timeout = min_t(u32, arg.max_rest_time * | ||||||
|  |  				(arg.n_channels - 1) + (req->duration + | ||||||
|  |  				ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) * | ||||||
|  | -				arg.n_channels, arg.max_scan_time + 200); | ||||||
|  | +				arg.n_channels, arg.max_scan_time); | ||||||
|  |   | ||||||
|  |  	} else { | ||||||
|  | -		/* Add a 200ms margin to account for event/command processing */ | ||||||
|  | -		scan_timeout = arg.max_scan_time + 200; | ||||||
|  | +		scan_timeout = arg.max_scan_time; | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | +	/* Add a 200ms margin to account for event/command processing */ | ||||||
|  | +	scan_timeout += 200; | ||||||
|  | + | ||||||
|  |  	ret = ath10k_start_scan(ar, &arg); | ||||||
|  |  	if (ret) { | ||||||
|  |  		ath10k_warn(ar, "failed to start hw scan: %d\n", ret); | ||||||
| @@ -0,0 +1,11 @@ | |||||||
|  | --- a/ath10k-5.7/mac.c	2021-07-06 11:12:56.022146449 -0700 | ||||||
|  | +++ b/ath10k-5.7/mac.c	2021-07-06 19:37:52.352753693 -0700 | ||||||
|  | @@ -8286,7 +8286,7 @@ | ||||||
|  |  				  struct ieee80211_channel *channel) | ||||||
|  |  { | ||||||
|  |  	int ret; | ||||||
|  | -	enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR; | ||||||
|  | +	enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; | ||||||
|  |   | ||||||
|  |  	lockdep_assert_held(&ar->conf_mutex); | ||||||
|  |   | ||||||
| @@ -0,0 +1,31 @@ | |||||||
|  | --- a/ath10k-5.7/wmi.c | ||||||
|  | +++ b/ath10k-5.7/wmi.c | ||||||
|  | @@ -6347,16 +6347,18 @@ | ||||||
|  |   | ||||||
|  |  	survey = &ar->survey[idx]; | ||||||
|  |   | ||||||
|  | -	survey->noise     = noise_floor; | ||||||
|  | -	survey->time      = div_u64(total, cc_freq_hz); | ||||||
|  | -	survey->time_busy = div_u64(busy, cc_freq_hz); | ||||||
|  | -	survey->time_rx   = div_u64(rx_bss, cc_freq_hz); | ||||||
|  | -	survey->time_tx   = div_u64(tx, cc_freq_hz); | ||||||
|  | -	survey->filled   |= (SURVEY_INFO_NOISE_DBM | | ||||||
|  | -			     SURVEY_INFO_TIME | | ||||||
|  | -			     SURVEY_INFO_TIME_BUSY | | ||||||
|  | -			     SURVEY_INFO_TIME_RX | | ||||||
|  | -			     SURVEY_INFO_TIME_TX); | ||||||
|  | +	survey->noise       = noise_floor; | ||||||
|  | +	survey->time        = div_u64(total, cc_freq_hz); | ||||||
|  | +	survey->time_busy   = div_u64(busy, cc_freq_hz); | ||||||
|  | +	survey->time_rx     = div_u64(rx, cc_freq_hz); | ||||||
|  | +	survey->time_bss_rx = div_u64(rx_bss, cc_freq_hz); | ||||||
|  | +	survey->time_tx     = div_u64(tx, cc_freq_hz); | ||||||
|  | +	survey->filled     |= (SURVEY_INFO_NOISE_DBM | | ||||||
|  | +			       SURVEY_INFO_TIME | | ||||||
|  | +			       SURVEY_INFO_TIME_BUSY | | ||||||
|  | +			       SURVEY_INFO_TIME_RX | | ||||||
|  | +			       SURVEY_INFO_TIME_TX | | ||||||
|  | +			       SURVEY_INFO_TIME_BSS_RX); | ||||||
|  |  exit: | ||||||
|  |  	spin_unlock_bh(&ar->data_lock); | ||||||
|  |  	complete(&ar->bss_survey_done); | ||||||
							
								
								
									
										14
									
								
								feeds/ipq40xx/ath10k-ct/patches/999-ath10k-threading.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								feeds/ipq40xx/ath10k-ct/patches/999-ath10k-threading.patch
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | Index: ath10k-ct-2021-05-22b-54a9ac02/ath10k-5.7/core.c | ||||||
|  | =================================================================== | ||||||
|  | --- ath10k-ct-2021-05-22b-54a9ac02.orig/ath10k-5.7/core.c | ||||||
|  | +++ ath10k-ct-2021-05-22b-54a9ac02/ath10k-5.7/core.c | ||||||
|  | @@ -4146,6 +4146,9 @@ struct ath10k *ath10k_core_create(size_t | ||||||
|  |  	INIT_WORK(&ar->stop_scan_work, ath10k_wmi_stop_scan_work); | ||||||
|  |   | ||||||
|  |  	init_dummy_netdev(&ar->napi_dev); | ||||||
|  | +	snprintf(ar->napi_dev.name, sizeof(ar->napi_dev.name), "%s", | ||||||
|  | +		 wiphy_name(ar->hw->wiphy)); | ||||||
|  | +	ar->napi_dev.threaded = 1; | ||||||
|  |   | ||||||
|  |  	ret = ath10k_coredump_create(ar); | ||||||
|  |  	if (ret) | ||||||
							
								
								
									
										182
									
								
								feeds/ipq40xx/ath10k-firmware/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								feeds/ipq40xx/ath10k-firmware/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,182 @@ | |||||||
|  | # | ||||||
|  | # Copyright (C) 2015 OpenWrt.org | ||||||
|  | # | ||||||
|  | # This is free software, licensed under the GNU General Public License v2. | ||||||
|  | # See /LICENSE for more information. | ||||||
|  | # | ||||||
|  |  | ||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=ath10k-firmware | ||||||
|  | PKG_SOURCE_DATE:=2019-10-03 | ||||||
|  | PKG_SOURCE_VERSION:=d622d160e9f552ead68d9ae81b715422892dc2ef | ||||||
|  | PKG_MIRROR_HASH:=2e504e071c3f896d629c4cfffe7ff4b5f1acdb4fecd3f01e8ff8c73e87a67cc7 | ||||||
|  | PKG_RELEASE:=1 | ||||||
|  |  | ||||||
|  | PKG_SOURCE_PROTO:=git | ||||||
|  | PKG_SOURCE_URL:=https://github.com/kvalo/ath10k-firmware.git | ||||||
|  |  | ||||||
|  | PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name> | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-default | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   URL:=$(PKG_SOURCE_URL) | ||||||
|  |   DEPENDS:= | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9887 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA9887 devices | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9888 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA9888 devices | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca988x | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA988x devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA99x0 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0/description | ||||||
|  | Standard ath10k firmware for QCA99x0 from QCA | ||||||
|  | This firmware conflicts with the CT 99x0 firmware, so select only | ||||||
|  | one. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9984 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA9984 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca4019 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for IPQ/QCA4019 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca6174 | ||||||
|  | $(Package/ath10k-firmware-default) | ||||||
|  |   TITLE:=ath10k firmware for QCA6174 devices | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | QCA99X0_BOARD_REV:=ddcec9efd245da9365c474f513a855a55f3ac7fe | ||||||
|  | QCA99X0_BOARD_FILE:=board-2.bin.$(QCA99X0_BOARD_REV) | ||||||
|  |  | ||||||
|  | define Download/qca99x0-board | ||||||
|  |   URL:=https://source.codeaurora.org/quic/qsdk/oss/firmware/ath10k-firmware/plain/ath10k/QCA99X0/hw2.0 | ||||||
|  |   URL_FILE:=board-2.bin?id=$(QCA99X0_BOARD_REV) | ||||||
|  |   FILE:=$(QCA99X0_BOARD_FILE) | ||||||
|  |   HASH:=03711ac21e60ef59d3815e235eb721c0c22851b5410299411085aa6f2af45401 | ||||||
|  | endef | ||||||
|  | $(eval $(call Download,qca99x0-board)) | ||||||
|  |  | ||||||
|  | define Build/Compile | ||||||
|  |  | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca4019/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA4019/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA4019/hw1.0/board-2.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/ | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA4019/hw1.0/3.5.3/firmware-5.bin_10.4-3.5.3-00057 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9887/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9887/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9887/hw1.0/10.2.4-1.0/firmware-5.bin_10.2.4-1.0-00047 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/firmware-5.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9887/hw1.0/board.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9887/hw1.0/board.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9888/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9888/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9888/hw2.0/board-2.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9888/hw2.0/3.5.3/firmware-5.bin_10.4-3.5.3-00053 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca988x/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA988X/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA988X/hw2.0/board.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/ | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA988X/hw2.0/10.2.4-1.0/firmware-5.bin_10.2.4-1.0-00047 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca6174/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA6174/hw2.1 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA6174/hw2.1/board-2.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA6174/hw2.1/ | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA6174/hw2.1/firmware-5.bin_SW_RM.1.1.1-00157-QCARMSWPZ-1 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA6174/hw2.1/firmware-5.bin | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA6174/hw3.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA6174/hw3.0/board-2.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA6174/hw3.0/ | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA6174/hw3.0/4.4.1.c1/firmware-6.bin_RM.4.4.1.c1-00042-QCARMSWP-1 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA6174/hw3.0/firmware-6.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca99x0/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA99X0/hw2.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(DL_DIR)/$(QCA99X0_BOARD_FILE) \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA99X0/hw2.0/boardData_AR900B_CUS239_5G_v2_001.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/board.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA99X0/hw2.0/firmware-5.bin_10.4.1.00030-1 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA99X0/hw2.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/ath10k-firmware-qca9984/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA9984/hw1.0 | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9984/hw1.0/board-2.bin \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/board-2.bin | ||||||
|  | 	$(INSTALL_DATA) \ | ||||||
|  | 		$(PKG_BUILD_DIR)/QCA9984/hw1.0/3.5.3/firmware-5.bin_10.4-3.5.3-00053 \ | ||||||
|  | 		$(1)/lib/firmware/ath10k/QCA9984/hw1.0/firmware-5.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca9887)) | ||||||
|  | #$(eval $(call BuildPackage,ath10k-firmware-qca9888)) | ||||||
|  | $(eval $(call BuildPackage,ath10k-firmware-qca988x)) | ||||||
|  | #$(eval $(call BuildPackage,ath10k-firmware-qca99x0)) | ||||||
|  | #$(eval $(call BuildPackage,ath10k-firmware-qca6174)) | ||||||
|  | #$(eval $(call BuildPackage,ath10k-firmware-qca9984)) | ||||||
|  | #$(eval $(call BuildPackage,ath10k-firmware-qca4019)) | ||||||
							
								
								
									
										231
									
								
								feeds/ipq40xx/batctl/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										231
									
								
								feeds/ipq40xx/batctl/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,231 @@ | |||||||
|  | # SPDX-License-Identifier: GPL-2.0-only | ||||||
|  |  | ||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=batctl | ||||||
|  | PKG_VERSION:=2020.2 | ||||||
|  | PKG_RELEASE:=1 | ||||||
|  |  | ||||||
|  | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | ||||||
|  | PKG_SOURCE_URL:=https://downloads.open-mesh.org/batman/releases/batman-adv-$(PKG_VERSION) | ||||||
|  | PKG_HASH:=d29cdb53ee68abd5027eae07d9fd645b3f154e0d577efa2666c1334bb6d60efd | ||||||
|  | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION) | ||||||
|  |  | ||||||
|  | PKG_MAINTAINER:=Simon Wunderlich <sw@simonwunderlich.de> | ||||||
|  | PKG_LICENSE:=GPL-2.0-only ISC MIT | ||||||
|  | PKG_LICENSE_FILES:=LICENSES/preferred/GPL-2.0 LICENSES/preferred/MIT LICENSES/deprecated/ISC | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | define Package/batctl/Default | ||||||
|  |   SECTION:=net | ||||||
|  |   CATEGORY:=Network | ||||||
|  |   URL:=https://www.open-mesh.org/ | ||||||
|  |   DEPENDS:=+libnl-tiny +libc +librt | ||||||
|  |   PROVIDES:=batctl | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl/description | ||||||
|  |   batctl is a more intuitive managment utility for B.A.T.M.A.N.-Advanced. | ||||||
|  |   It is an easier method for configuring batman-adv and provides some | ||||||
|  |   additional tools for debugging as well. This package builds | ||||||
|  |   version $(PKG_VERSION) of the user space utility. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-tiny | ||||||
|  | $(call Package/batctl/Default) | ||||||
|  |   TITLE:=B.A.T.M.A.N. Advanced user space configuration tool (Minimal) | ||||||
|  |   VARIANT:=tiny | ||||||
|  |   ALTERNATIVES:=100:/usr/sbin/batctl:/usr/libexec/batctl-tiny | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-tiny/description | ||||||
|  | $(Package/batctl/description) | ||||||
|  |   Only configuration relevant subcommands are enabled. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-default | ||||||
|  | $(call Package/batctl/Default) | ||||||
|  |   TITLE:=B.A.T.M.A.N. Advanced user space configuration tool (Default) | ||||||
|  |   VARIANT:=default | ||||||
|  |   ALTERNATIVES:=200:/usr/sbin/batctl:/usr/libexec/batctl-default | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-default/description | ||||||
|  | $(Package/batctl/description) | ||||||
|  |   Standard subcommands for configuration and online debugging are enabled. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-full | ||||||
|  | $(call Package/batctl/Default) | ||||||
|  |   TITLE:=B.A.T.M.A.N. Advanced user space configuration tool (Full) | ||||||
|  |   VARIANT:=full | ||||||
|  |   ALTERNATIVES:=300:/usr/sbin/batctl:/usr/libexec/batctl-full | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-full/description | ||||||
|  | $(Package/batctl/description) | ||||||
|  |   Subcommands for configuration, online and offline debugging are enabled. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | # The linker can identify unused sections of a binary when each symbol is stored | ||||||
|  | # in a separate section. This mostly removes unused linker sections and reduces | ||||||
|  | # the size by ~3% on mipsel. | ||||||
|  |  | ||||||
|  | TARGET_CFLAGS  += -ffunction-sections -fdata-sections | ||||||
|  | TARGET_LDFLAGS += -Wl,--gc-sections | ||||||
|  |  | ||||||
|  | # Link-time optimization allows to move parts of the optimization from the single | ||||||
|  | # source file to the global source view. This is done by emitting the GIMPLE | ||||||
|  | # representation in each object file and analyzing it again during the link step. | ||||||
|  |  | ||||||
|  | TARGET_CFLAGS  += -flto | ||||||
|  | TARGET_LDFLAGS += -fuse-linker-plugin | ||||||
|  |  | ||||||
|  | MAKE_VARS += \ | ||||||
|  |         LIBNL_NAME="libnl-tiny" \ | ||||||
|  |         LIBNL_GENL_NAME="libnl-tiny" | ||||||
|  |  | ||||||
|  | MAKE_FLAGS += \ | ||||||
|  |         REVISION="$(PKG_VERSION)-openwrt-$(PKG_RELEASE)" | ||||||
|  |  | ||||||
|  | config-n := \ | ||||||
|  | 	aggregation \ | ||||||
|  | 	ap_isolation \ | ||||||
|  | 	backbonetable \ | ||||||
|  | 	bisect_iv \ | ||||||
|  | 	bonding \ | ||||||
|  | 	bridge_loop_avoidance \ | ||||||
|  | 	claimtable \ | ||||||
|  | 	dat_cache \ | ||||||
|  | 	distributed_arp_table \ | ||||||
|  | 	elp_interval \ | ||||||
|  | 	event \ | ||||||
|  | 	fragmentation \ | ||||||
|  | 	gateways \ | ||||||
|  | 	gw_mode \ | ||||||
|  | 	hop_penalty \ | ||||||
|  | 	interface \ | ||||||
|  | 	isolation_mark \ | ||||||
|  | 	loglevel \ | ||||||
|  | 	mcast_flags \ | ||||||
|  | 	multicast_fanout \ | ||||||
|  | 	multicast_forceflood \ | ||||||
|  | 	multicast_mode \ | ||||||
|  | 	nc_nodes \ | ||||||
|  | 	neighbors \ | ||||||
|  | 	network_coding \ | ||||||
|  | 	orig_interval \ | ||||||
|  | 	originators \ | ||||||
|  | 	ping \ | ||||||
|  | 	routing_algo \ | ||||||
|  | 	statistics \ | ||||||
|  | 	tcpdump \ | ||||||
|  | 	throughput_override \ | ||||||
|  | 	throughputmeter \ | ||||||
|  | 	traceroute \ | ||||||
|  | 	transglobal \ | ||||||
|  | 	translate \ | ||||||
|  | 	translocal \ | ||||||
|  |  | ||||||
|  | config-settings := \ | ||||||
|  | 	aggregation \ | ||||||
|  | 	ap_isolation \ | ||||||
|  | 	bonding \ | ||||||
|  | 	bridge_loop_avoidance \ | ||||||
|  | 	distributed_arp_table \ | ||||||
|  | 	elp_interval \ | ||||||
|  | 	fragmentation \ | ||||||
|  | 	gw_mode \ | ||||||
|  | 	hop_penalty \ | ||||||
|  | 	interface \ | ||||||
|  | 	isolation_mark \ | ||||||
|  | 	loglevel \ | ||||||
|  | 	multicast_fanout \ | ||||||
|  | 	multicast_forceflood \ | ||||||
|  | 	multicast_mode \ | ||||||
|  | 	network_coding \ | ||||||
|  | 	orig_interval \ | ||||||
|  | 	routing_algo \ | ||||||
|  | 	throughput_override \ | ||||||
|  |  | ||||||
|  | config-tables := \ | ||||||
|  | 	backbonetable \ | ||||||
|  | 	claimtable \ | ||||||
|  | 	dat_cache \ | ||||||
|  | 	gateways \ | ||||||
|  | 	loglevel \ | ||||||
|  | 	nc_nodes \ | ||||||
|  | 	neighbors \ | ||||||
|  | 	originators \ | ||||||
|  | 	statistics \ | ||||||
|  | 	transglobal \ | ||||||
|  | 	translocal \ | ||||||
|  |  | ||||||
|  | config-tools := \ | ||||||
|  | 	event \ | ||||||
|  | 	ping \ | ||||||
|  | 	tcpdump \ | ||||||
|  | 	throughputmeter \ | ||||||
|  | 	traceroute \ | ||||||
|  | 	translate \ | ||||||
|  |  | ||||||
|  | config-extratools := \ | ||||||
|  | 	bisect_iv \ | ||||||
|  |  | ||||||
|  | ifeq ($(BUILD_VARIANT),tiny) | ||||||
|  |  | ||||||
|  | config-y := \ | ||||||
|  | 	$(config-settings) \ | ||||||
|  |  | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifeq ($(BUILD_VARIANT),default) | ||||||
|  |  | ||||||
|  | config-y := \ | ||||||
|  | 	$(config-settings) \ | ||||||
|  | 	$(config-tables) \ | ||||||
|  | 	$(config-tools) \ | ||||||
|  |  | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | ifeq ($(BUILD_VARIANT),full) | ||||||
|  |  | ||||||
|  | config-y := \ | ||||||
|  | 	$(config-settings) \ | ||||||
|  | 	$(config-tables) \ | ||||||
|  | 	$(config-tools) \ | ||||||
|  | 	$(config-extratools) \ | ||||||
|  |  | ||||||
|  | endif | ||||||
|  |  | ||||||
|  | define ConfigVars | ||||||
|  | $(subst $(space),,$(foreach opt,$(config-$(1)),CONFIG_$(opt)=$(1) | ||||||
|  | )) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define batctl_config | ||||||
|  | $(call ConfigVars,n)$(call ConfigVars,y) | ||||||
|  | endef | ||||||
|  | $(eval $(call shexport,batctl_config)) | ||||||
|  |  | ||||||
|  | MAKE_FLAGS += $$$$$(call shvar,batctl_config) | ||||||
|  |  | ||||||
|  | define Package/batctl-tiny/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/usr/libexec | ||||||
|  | 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/batctl $(1)/usr/libexec/batctl-tiny | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-default/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/usr/libexec | ||||||
|  | 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/batctl $(1)/usr/libexec/batctl-default | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/batctl-full/install | ||||||
|  | 	$(INSTALL_DIR) $(1)/usr/libexec | ||||||
|  | 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/batctl $(1)/usr/libexec/batctl-full | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | $(eval $(call BuildPackage,batctl-default)) | ||||||
|  | $(eval $(call BuildPackage,batctl-tiny)) | ||||||
|  | $(eval $(call BuildPackage,batctl-full)) | ||||||
							
								
								
									
										110
									
								
								feeds/ipq40xx/batman-adv/Config.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								feeds/ipq40xx/batman-adv/Config.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | |||||||
|  | # SPDX-License-Identifier: GPL-2.0 | ||||||
|  | # Copyright (C) 2007-2019  B.A.T.M.A.N. contributors: | ||||||
|  | # | ||||||
|  | # Marek Lindner, Simon Wunderlich | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # B.A.T.M.A.N meshing protocol | ||||||
|  | # | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_BATMAN_V | ||||||
|  | 	bool "B.A.T.M.A.N. V protocol" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	default y | ||||||
|  | 	help | ||||||
|  | 	  This option enables the B.A.T.M.A.N. V protocol, the successor | ||||||
|  | 	  of the currently used B.A.T.M.A.N. IV protocol. The main | ||||||
|  | 	  changes include splitting of the OGM protocol into a neighbor | ||||||
|  | 	  discovery protocol (Echo Location Protocol, ELP) and a new OGM | ||||||
|  | 	  Protocol OGMv2 for flooding protocol information through the | ||||||
|  | 	  network, as well as a throughput based metric. | ||||||
|  | 	  B.A.T.M.A.N. V is currently considered experimental and not | ||||||
|  | 	  compatible to B.A.T.M.A.N. IV networks. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_BLA | ||||||
|  | 	bool "Bridge Loop Avoidance" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	select PACKAGE_kmod-lib-crc16 | ||||||
|  | 	default y | ||||||
|  | 	help | ||||||
|  | 	  This option enables BLA (Bridge Loop Avoidance), a mechanism | ||||||
|  | 	  to avoid Ethernet frames looping when mesh nodes are connected | ||||||
|  | 	  to both the same LAN and the same mesh. If you will never use | ||||||
|  | 	  more than one mesh node in the same LAN, you can safely remove | ||||||
|  | 	  this feature and save some space. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_DAT | ||||||
|  | 	bool "Distributed ARP Table" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	default y | ||||||
|  | 	help | ||||||
|  | 	  This option enables DAT (Distributed ARP Table), a DHT based | ||||||
|  | 	  mechanism that increases ARP reliability on sparse wireless | ||||||
|  | 	  mesh networks. If you think that your network does not need | ||||||
|  | 	  this option you can safely remove it and save some space. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_NC | ||||||
|  | 	bool "Network Coding" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	help | ||||||
|  | 	  This option enables network coding, a mechanism that aims to | ||||||
|  | 	  increase the overall network throughput by fusing multiple | ||||||
|  | 	  packets in one transmission. | ||||||
|  | 	  Note that interfaces controlled by batman-adv must be manually | ||||||
|  | 	  configured to have promiscuous mode enabled in order to make | ||||||
|  | 	  network coding work. | ||||||
|  | 	  If you think that your network does not need this feature you | ||||||
|  | 	  can safely disable it and save some space. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_MCAST | ||||||
|  | 	bool "Multicast optimisation" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	default y | ||||||
|  | 	help | ||||||
|  | 	  This option enables the multicast optimisation which aims to | ||||||
|  | 	  reduce the air overhead while improving the reliability of | ||||||
|  | 	  multicast messages. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_DEBUGFS | ||||||
|  | 	bool "batman-adv debugfs entries" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	select KERNEL_DEBUG_FS | ||||||
|  | 	help | ||||||
|  | 	  Enable this to export routing related debug tables via debugfs. | ||||||
|  | 	  The information for each soft-interface and used hard-interface can be | ||||||
|  | 	  found under batman_adv/ | ||||||
|  |  | ||||||
|  | 	  If unsure, say N. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_DEBUG | ||||||
|  | 	bool "B.A.T.M.A.N. debugging" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	help | ||||||
|  | 	  This is an option for use by developers; most people should | ||||||
|  | 	  say N here. This enables compilation of support for | ||||||
|  | 	  outputting debugging information to the debugfs log or tracing | ||||||
|  | 	  buffer. The output is controlled via the batadv netdev specific | ||||||
|  | 	  log_level setting. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_SYSFS | ||||||
|  | 	bool "batman-adv sysfs entries" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	help | ||||||
|  | 	  Say Y here if you want to enable batman-adv device configuration and | ||||||
|  | 	  status interface through sysfs attributes. It is replaced by the | ||||||
|  | 	  batadv generic netlink family but still used by various userspace | ||||||
|  | 	  tools and scripts. | ||||||
|  |  | ||||||
|  | 	  If unsure, say Y. | ||||||
|  |  | ||||||
|  | config BATMAN_ADV_TRACING | ||||||
|  | 	bool "B.A.T.M.A.N. tracing support" | ||||||
|  | 	depends on PACKAGE_kmod-batman-adv | ||||||
|  | 	select KERNEL_FTRACE | ||||||
|  | 	select KERNEL_ENABLE_DEFAULT_TRACERS | ||||||
|  | 	help | ||||||
|  | 	  This is an option for use by developers; most people should | ||||||
|  | 	  say N here. Select this option to gather traces like the debug | ||||||
|  | 	  messages using the generic tracing infrastructure of the kernel. | ||||||
|  | 	  BATMAN_ADV_DEBUG must also be selected to get trace events for | ||||||
|  | 	  batadv_dbg. | ||||||
							
								
								
									
										91
									
								
								feeds/ipq40xx/batman-adv/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								feeds/ipq40xx/batman-adv/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | |||||||
|  | # SPDX-License-Identifier: GPL-2.0-only | ||||||
|  |  | ||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=batman-adv | ||||||
|  | PKG_VERSION:=2020.2 | ||||||
|  | PKG_RELEASE:=1 | ||||||
|  |  | ||||||
|  | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | ||||||
|  | PKG_SOURCE_URL:=https://downloads.open-mesh.org/batman/releases/batman-adv-$(PKG_VERSION) | ||||||
|  | PKG_HASH:=a73f5ce72c6efa9dd7bd7cc8daa667d0982e12e40811c978bb652607bb5666a3 | ||||||
|  | PKG_EXTMOD_SUBDIRS:=net/batman-adv | ||||||
|  |  | ||||||
|  | PKG_MAINTAINER:=Simon Wunderlich <sw@simonwunderlich.de> | ||||||
|  | PKG_LICENSE:=GPL-2.0-only MIT | ||||||
|  | PKG_LICENSE_FILES:=LICENSES/preferred/GPL-2.0 LICENSES/preferred/MIT | ||||||
|  |  | ||||||
|  | STAMP_CONFIGURED_DEPENDS := $(STAGING_DIR)/usr/include/mac80211-backport/backport/autoconf.h | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/kernel.mk | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | define KernelPackage/batman-adv | ||||||
|  |   SUBMENU:=Network Support | ||||||
|  |   TITLE:=B.A.T.M.A.N. Adv | ||||||
|  |   URL:=https://www.open-mesh.org/ | ||||||
|  |   DEPENDS:=+BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-lib-crc32c +kmod-cfg80211 +batctl | ||||||
|  |   FILES:=$(PKG_BUILD_DIR)/net/batman-adv/batman-adv.$(LINUX_KMOD_SUFFIX) | ||||||
|  |   AUTOLOAD:=$(call AutoProbe,batman-adv) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define KernelPackage/batman-adv/description | ||||||
|  |   B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is | ||||||
|  |   a routing protocol for multi-hop ad-hoc mesh networks. The | ||||||
|  |   networks may be wired or wireless. See | ||||||
|  |   https://www.open-mesh.org/ for more information and user space | ||||||
|  |   tools. This package builds version $(PKG_VERSION) of the kernel | ||||||
|  |   module. | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define KernelPackage/batman-adv/config | ||||||
|  | 	source "$(SOURCE)/Config.in" | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Package/kmod-batman-adv/conffiles | ||||||
|  | /etc/config/batman-adv | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | PKG_EXTRA_KCONFIG:= \ | ||||||
|  | 	CONFIG_BATMAN_ADV=m \ | ||||||
|  | 	CONFIG_BATMAN_ADV_DEBUG=$(if $(CONFIG_BATMAN_ADV_DEBUG),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_DEBUGFS=$(if $(CONFIG_BATMAN_ADV_DEBUGFS),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_BLA=$(if $(CONFIG_BATMAN_ADV_BLA),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_DAT=$(if $(CONFIG_BATMAN_ADV_DAT),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_MCAST=$(if $(CONFIG_BATMAN_ADV_MCAST),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_NC=$(if $(CONFIG_BATMAN_ADV_NC),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_BATMAN_V=$(if $(CONFIG_BATMAN_ADV_BATMAN_V),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_SYSFS=$(if $(CONFIG_BATMAN_ADV_SYSFS),y,n) \ | ||||||
|  | 	CONFIG_BATMAN_ADV_TRACING=$(if $(CONFIG_BATMAN_ADV_TRACING),y,n) \ | ||||||
|  |  | ||||||
|  | PKG_EXTRA_CFLAGS:= \ | ||||||
|  | 	$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(PKG_EXTRA_KCONFIG)))) \ | ||||||
|  | 	$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(PKG_EXTRA_KCONFIG)))) \ | ||||||
|  |  | ||||||
|  | NOSTDINC_FLAGS = \ | ||||||
|  | 	-I$(PKG_BUILD_DIR)/net/batman-adv \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211-backport \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211-backport/uapi \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211 \ | ||||||
|  | 	-I$(STAGING_DIR)/usr/include/mac80211/uapi \ | ||||||
|  | 	-I$(PKG_BUILD_DIR)/include/ \ | ||||||
|  | 	-include backport/autoconf.h \ | ||||||
|  | 	-include backport/backport.h \ | ||||||
|  | 	-include $(PKG_BUILD_DIR)/compat-hacks.h \ | ||||||
|  | 	-DBATADV_SOURCE_VERSION=\\\"$(PKG_VERSION)-openwrt-$(PKG_RELEASE)\\\" | ||||||
|  |  | ||||||
|  | define Build/Compile | ||||||
|  | 	$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \ | ||||||
|  | 		$(KERNEL_MAKE_FLAGS) \ | ||||||
|  | 		M="$(PKG_BUILD_DIR)/net/batman-adv" \ | ||||||
|  | 		$(PKG_EXTRA_KCONFIG) \ | ||||||
|  | 		EXTRA_CFLAGS="$(PKG_EXTRA_CFLAGS)" \ | ||||||
|  | 		NOSTDINC_FLAGS="$(NOSTDINC_FLAGS)" \ | ||||||
|  | 		modules | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define KernelPackage/batman-adv/install | ||||||
|  | 	$(CP) ./files/. $(1)/ | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | $(eval $(call KernelPackage,batman-adv)) | ||||||
							
								
								
									
										97
									
								
								feeds/ipq40xx/batman-adv/files/etc/uci-defaults/99-migrate-batadv_hardif
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										97
									
								
								feeds/ipq40xx/batman-adv/files/etc/uci-defaults/99-migrate-batadv_hardif
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,97 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | # This UCI-Defaults script will split the batadv proto network interfaces | ||||||
|  | # in batadv_hardif and batadv proto. The configuration options from | ||||||
|  | # /etc/config/batman-adv will be moved to the latter. | ||||||
|  |  | ||||||
|  | . /lib/functions.sh | ||||||
|  |  | ||||||
|  | proto_batadv_to_batadv_hardif() { | ||||||
|  |     local section="$1" | ||||||
|  |     local proto | ||||||
|  |     local mesh | ||||||
|  |     local routing_algo | ||||||
|  |  | ||||||
|  |     config_get proto "${section}" proto | ||||||
|  |     config_get mesh "${section}" mesh | ||||||
|  |     config_get routing_algo "${section}" routing_algo | ||||||
|  |  | ||||||
|  |     if [ -z "$mesh" -o "${proto}" != "batadv" ]; then | ||||||
|  |         continue | ||||||
|  |     fi | ||||||
|  |  | ||||||
|  |     uci set network."${section}".proto="batadv_hardif" | ||||||
|  |     uci rename network."${section}".mesh="master" | ||||||
|  |     uci delete network."${section}".routing_algo | ||||||
|  |  | ||||||
|  |     # create new section or adjust existing one | ||||||
|  |     uci set network."${mesh}"=interface | ||||||
|  |     uci set network."${mesh}".proto=batadv | ||||||
|  |     [ -n "${routing_algo}" ]  && uci set network."${mesh}".routing_algo="${routing_algo}" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | mv_batadv_config_section() { | ||||||
|  |     local section="$1" | ||||||
|  |     local aggregated_ogms | ||||||
|  |     local ap_isolation | ||||||
|  |     local bonding | ||||||
|  |     local bridge_loop_avoidance | ||||||
|  |     local distributed_arp_table | ||||||
|  |     local fragmentation | ||||||
|  |     local gw_bandwidth | ||||||
|  |     local gw_mode | ||||||
|  |     local gw_sel_class | ||||||
|  |     local hop_penalty | ||||||
|  |     local isolation_mark | ||||||
|  |     local log_level | ||||||
|  |     local multicast_mode | ||||||
|  |     local network_coding | ||||||
|  |     local orig_interval | ||||||
|  |  | ||||||
|  |     config_get aggregated_ogms "${section}" aggregated_ogms | ||||||
|  |     config_get ap_isolation "${section}" ap_isolation | ||||||
|  |     config_get bonding "${section}" bonding | ||||||
|  |     config_get bridge_loop_avoidance "${section}" bridge_loop_avoidance | ||||||
|  |     config_get distributed_arp_table "${section}" distributed_arp_table | ||||||
|  |     config_get fragmentation "${section}" fragmentation | ||||||
|  |     config_get gw_bandwidth "${section}" gw_bandwidth | ||||||
|  |     config_get gw_mode "${section}" gw_mode | ||||||
|  |     config_get gw_sel_class "${section}" gw_sel_class | ||||||
|  |     config_get hop_penalty "${section}" hop_penalty | ||||||
|  |     config_get isolation_mark "${section}" isolation_mark | ||||||
|  |     config_get log_level "${section}" log_level | ||||||
|  |     config_get multicast_mode "${section}" multicast_mode | ||||||
|  |     config_get network_coding "${section}" network_coding | ||||||
|  |     config_get orig_interval "${section}" orig_interval | ||||||
|  |  | ||||||
|  |     # update section in case it exists | ||||||
|  |     [ -n "${aggregated_ogms}" ]  && uci set network."${section}".aggregated_ogms="${aggregated_ogms}" | ||||||
|  |     [ -n "${ap_isolation}" ]  && uci set network."${section}".ap_isolation="${ap_isolation}" | ||||||
|  |     [ -n "${bonding}" ]  && uci set network."${section}".bonding="${bonding}" | ||||||
|  |     [ -n "${bridge_loop_avoidance}" ]  && uci set network."${section}".bridge_loop_avoidance="${bridge_loop_avoidance}" | ||||||
|  |     [ -n "${distributed_arp_table}" ]  && uci set network."${section}".distributed_arp_table="${distributed_arp_table}" | ||||||
|  |     [ -n "${fragmentation}" ]  && uci set network."${section}".fragmentation="${fragmentation}" | ||||||
|  |     [ -n "${gw_bandwidth}" ]  && uci set network."${section}".gw_bandwidth="${gw_bandwidth}" | ||||||
|  |     [ -n "${gw_mode}" ]  && uci set network."${section}".gw_mode="${gw_mode}" | ||||||
|  |     [ -n "${gw_sel_class}" ]  && uci set network."${section}".gw_sel_class="${gw_sel_class}" | ||||||
|  |     [ -n "${hop_penalty}" ]  && uci set network."${section}".hop_penalty="${hop_penalty}" | ||||||
|  |     [ -n "${isolation_mark}" ]  && uci set network."${section}".isolation_mark="${isolation_mark}" | ||||||
|  |     [ -n "${log_level}" ]  && uci set network."${section}".log_level="${log_level}" | ||||||
|  |     [ -n "${multicast_mode}" ]  && uci set network."${section}".multicast_mode="${multicast_mode}" | ||||||
|  |     [ -n "${network_coding}" ]  && uci set network."${section}".network_coding="${network_coding}" | ||||||
|  |     [ -n "${orig_interval}" ]  && uci set network."${section}".orig_interval="${orig_interval}" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | if [ -f /etc/config/batman-adv ]; then | ||||||
|  |     config_load network | ||||||
|  |     config_foreach proto_batadv_to_batadv_hardif 'interface' | ||||||
|  |     uci commit network | ||||||
|  |  | ||||||
|  |     config_load batman-adv | ||||||
|  |     config_foreach mv_batadv_config_section 'mesh' | ||||||
|  |     uci commit network | ||||||
|  |  | ||||||
|  |     rm -f /etc/config/batman-adv | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | exit 0 | ||||||
							
								
								
									
										123
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										123
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,123 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | [ -n "$INCLUDE_ONLY" ] || { | ||||||
|  | 	. /lib/functions.sh | ||||||
|  | 	. ../netifd-proto.sh | ||||||
|  | 	init_proto "$@" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_init_config() { | ||||||
|  | 	no_device=1 | ||||||
|  | 	available=1 | ||||||
|  |  | ||||||
|  | 	proto_config_add_boolean 'aggregated_ogms:bool' | ||||||
|  | 	proto_config_add_boolean 'ap_isolation:bool' | ||||||
|  | 	proto_config_add_boolean 'bonding:bool' | ||||||
|  | 	proto_config_add_boolean 'bridge_loop_avoidance:bool' | ||||||
|  | 	proto_config_add_boolean 'distributed_arp_table:bool' | ||||||
|  | 	proto_config_add_boolean 'fragmentation:bool' | ||||||
|  | 	proto_config_add_string 'gw_bandwidth' | ||||||
|  | 	proto_config_add_string 'gw_mode' | ||||||
|  | 	proto_config_add_int 'gw_sel_class' | ||||||
|  | 	proto_config_add_int 'hop_penalty' | ||||||
|  | 	proto_config_add_string 'isolation_mark' | ||||||
|  | 	proto_config_add_string 'log_level' | ||||||
|  | 	proto_config_add_int 'multicast_fanout' | ||||||
|  | 	proto_config_add_boolean 'multicast_mode:bool' | ||||||
|  | 	proto_config_add_boolean 'network_coding:bool' | ||||||
|  | 	proto_config_add_int 'orig_interval' | ||||||
|  | 	proto_config_add_string 'routing_algo' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_setup() { | ||||||
|  | 	local config="$1" | ||||||
|  | 	local iface="$config" | ||||||
|  |  | ||||||
|  | 	local aggregated_ogms | ||||||
|  | 	local ap_isolation | ||||||
|  | 	local bonding | ||||||
|  | 	local bridge_loop_avoidance | ||||||
|  | 	local distributed_arp_table | ||||||
|  | 	local fragmentation | ||||||
|  | 	local gw_bandwidth | ||||||
|  | 	local gw_mode | ||||||
|  | 	local gw_sel_class | ||||||
|  | 	local hop_penalty | ||||||
|  | 	local isolation_mark | ||||||
|  | 	local log_level | ||||||
|  | 	local multicast_fanout | ||||||
|  | 	local multicast_mode | ||||||
|  | 	local network_coding | ||||||
|  | 	local orig_interval | ||||||
|  | 	local routing_algo | ||||||
|  |  | ||||||
|  | 	json_get_vars aggregated_ogms | ||||||
|  | 	json_get_vars ap_isolation | ||||||
|  | 	json_get_vars bonding | ||||||
|  | 	json_get_vars bridge_loop_avoidance | ||||||
|  | 	json_get_vars distributed_arp_table | ||||||
|  | 	json_get_vars fragmentation | ||||||
|  | 	json_get_vars gw_bandwidth | ||||||
|  | 	json_get_vars gw_mode | ||||||
|  | 	json_get_vars gw_sel_class | ||||||
|  | 	json_get_vars hop_penalty | ||||||
|  | 	json_get_vars isolation_mark | ||||||
|  | 	json_get_vars log_level | ||||||
|  | 	json_get_vars multicast_fanout | ||||||
|  | 	json_get_vars multicast_mode | ||||||
|  | 	json_get_vars network_coding | ||||||
|  | 	json_get_vars orig_interval | ||||||
|  | 	json_get_vars routing_algo | ||||||
|  |  | ||||||
|  | 	set_default routing_algo 'BATMAN_IV' | ||||||
|  |  | ||||||
|  | 	batctl routing_algo "$routing_algo" | ||||||
|  | 	batctl meshif "$iface" interface create | ||||||
|  |  | ||||||
|  | 	[ -n "$aggregated_ogms" ] && batctl meshif "$iface" aggregation "$aggregated_ogms" | ||||||
|  | 	[ -n "$ap_isolation" ] && batctl meshif "$iface" ap_isolation "$ap_isolation" | ||||||
|  | 	[ -n "$bonding" ] && batctl meshif "$iface" bonding "$bonding" | ||||||
|  | 	[ -n "$bridge_loop_avoidance" ] &&  batctl meshif "$iface" bridge_loop_avoidance "$bridge_loop_avoidance" 2>&- | ||||||
|  | 	[ -n "$distributed_arp_table" ] && batctl meshif "$iface" distributed_arp_table "$distributed_arp_table" 2>&- | ||||||
|  | 	[ -n "$fragmentation" ] && batctl meshif "$iface" fragmentation "$fragmentation" | ||||||
|  |  | ||||||
|  | 	case "$gw_mode" in | ||||||
|  | 	server) | ||||||
|  | 		if [ -n "$gw_bandwidth" ]; then | ||||||
|  | 			batctl meshif "$iface" gw_mode "server" "$gw_bandwidth" | ||||||
|  | 		else | ||||||
|  | 			batctl meshif "$iface" gw_mode "server" | ||||||
|  | 		fi | ||||||
|  | 		;; | ||||||
|  | 	client) | ||||||
|  | 		if [ -n "$gw_sel_class" ]; then | ||||||
|  | 			batctl meshif "$iface" gw_mode "client" "$gw_sel_class" | ||||||
|  | 		else | ||||||
|  | 			batctl meshif "$iface" gw_mode "client" | ||||||
|  | 		fi | ||||||
|  | 		;; | ||||||
|  | 	*) | ||||||
|  | 		batctl meshif "$iface" gw_mode "off" | ||||||
|  | 		;; | ||||||
|  | 	esac | ||||||
|  |  | ||||||
|  | 	[ -n "$hop_penalty" ] && batctl meshif "$iface" hop_penalty "$hop_penalty" | ||||||
|  | 	[ -n "$isolation_mark" ] && batctl meshif "$iface" isolation_mark "$isolation_mark" | ||||||
|  | 	[ -n "$multicast_fanout" ] && batctl meshif "$iface" multicast_fanout "$multicast_fanout" | ||||||
|  | 	[ -n "$multicast_mode" ] && batctl meshif "$iface" multicast_mode "$multicast_mode" 2>&- | ||||||
|  | 	[ -n "$network_coding" ] && batctl meshif "$iface" network_coding "$network_coding" 2>&- | ||||||
|  | 	[ -n "$log_level" ] && batctl meshif "$iface" loglevel "$log_level" 2>&- | ||||||
|  | 	[ -n "$orig_interval" ] && batctl meshif "$iface" orig_interval "$orig_interval" | ||||||
|  |  | ||||||
|  | 	proto_init_update "$iface" 1 | ||||||
|  | 	proto_send_update "$config" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_teardown() { | ||||||
|  | 	local config="$1" | ||||||
|  | 	local iface="$config" | ||||||
|  |  | ||||||
|  | 	batctl meshif "$iface" interface destroy | ||||||
|  | } | ||||||
|  |  | ||||||
|  | add_protocol batadv | ||||||
							
								
								
									
										49
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv_hardif.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										49
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv_hardif.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,49 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | [ -n "$INCLUDE_ONLY" ] || { | ||||||
|  | 	. /lib/functions.sh | ||||||
|  | 	. ../netifd-proto.sh | ||||||
|  | 	init_proto "$@" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_hardif_init_config() { | ||||||
|  | 	proto_config_add_int 'elp_interval' | ||||||
|  | 	proto_config_add_string "master" | ||||||
|  | 	proto_config_add_string 'throughput_override' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_hardif_setup() { | ||||||
|  | 	local config="$1" | ||||||
|  | 	local iface="$2" | ||||||
|  |  | ||||||
|  | 	local elp_interval | ||||||
|  | 	local master | ||||||
|  | 	local throughput_override | ||||||
|  |  | ||||||
|  | 	json_get_vars elp_interval | ||||||
|  | 	json_get_vars master | ||||||
|  | 	json_get_vars throughput_override | ||||||
|  |  | ||||||
|  | 	( proto_add_host_dependency "$config" '' "$master" ) | ||||||
|  |  | ||||||
|  | 	batctl meshif "$master" interface -M add "$iface" | ||||||
|  |  | ||||||
|  | 	[ -n "$elp_interval" ] && batctl hardif "$iface" elp_interval "$elp_interval" | ||||||
|  | 	[ -n "$throughput_override" ] && batctl hardif "$iface" throughput_override "$throughput_override" | ||||||
|  |  | ||||||
|  | 	proto_init_update "$iface" 1 | ||||||
|  | 	proto_send_update "$config" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_hardif_teardown() { | ||||||
|  | 	local config="$1" | ||||||
|  | 	local iface="$2" | ||||||
|  |  | ||||||
|  | 	local master | ||||||
|  |  | ||||||
|  | 	json_get_vars master | ||||||
|  |  | ||||||
|  | 	batctl meshif "$master" interface -M del "$iface" || true | ||||||
|  | } | ||||||
|  |  | ||||||
|  | add_protocol batadv_hardif | ||||||
							
								
								
									
										25
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv_vlan.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								feeds/ipq40xx/batman-adv/files/lib/netifd/proto/batadv_vlan.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | . /lib/functions.sh | ||||||
|  | . ../netifd-proto.sh | ||||||
|  | init_proto "$@" | ||||||
|  |  | ||||||
|  | proto_batadv_vlan_init_config() { | ||||||
|  | 	proto_config_add_boolean 'ap_isolation:bool' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | proto_batadv_vlan_setup() { | ||||||
|  | 	local config="$1" | ||||||
|  | 	local iface="$2" | ||||||
|  |  | ||||||
|  | 	# batadv_vlan options | ||||||
|  | 	local ap_isolation | ||||||
|  |  | ||||||
|  | 	json_get_vars ap_isolation | ||||||
|  |  | ||||||
|  | 	[ -n "$ap_isolation" ] && batctl vlan "$iface" ap_isolation "$ap_isolation" | ||||||
|  | 	proto_init_update "$iface" 1 | ||||||
|  | 	proto_send_update "$config" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | add_protocol batadv_vlan | ||||||
							
								
								
									
										181
									
								
								feeds/ipq40xx/batman-adv/src/compat-hacks.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								feeds/ipq40xx/batman-adv/src/compat-hacks.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,181 @@ | |||||||
|  | /* Please avoid adding hacks here - instead add it to mac80211/backports.git */ | ||||||
|  |  | ||||||
|  | #undef CONFIG_MODULE_STRIPPED | ||||||
|  |  | ||||||
|  | #include <linux/version.h>	/* LINUX_VERSION_CODE */ | ||||||
|  | #include <linux/types.h> | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) | ||||||
|  |  | ||||||
|  | #include <linux/netdevice.h> | ||||||
|  |  | ||||||
|  | #define netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info, extack) ({\ | ||||||
|  | 	BUILD_BUG_ON(extack != NULL); \ | ||||||
|  | 	netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info); \ | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(4, 15, 0) */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) | ||||||
|  |  | ||||||
|  | #ifndef sizeof_field | ||||||
|  | #define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(4, 16, 0) */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0) | ||||||
|  |  | ||||||
|  | #include_next <linux/igmp.h> | ||||||
|  | #include_next <net/addrconf.h> | ||||||
|  |  | ||||||
|  | static inline int batadv_ipv6_mc_check_mld1(struct sk_buff *skb) | ||||||
|  | { | ||||||
|  | 	return ipv6_mc_check_mld(skb, NULL); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static inline int batadv_ipv6_mc_check_mld2(struct sk_buff *skb, | ||||||
|  | 					    struct sk_buff **skb_trimmed) | ||||||
|  | { | ||||||
|  | 	return ipv6_mc_check_mld(skb, skb_trimmed); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #define ipv6_mc_check_mld_get(_1, _2, ipv6_mc_check_mld_name, ...) ipv6_mc_check_mld_name | ||||||
|  | #define ipv6_mc_check_mld(...) \ | ||||||
|  | 	ipv6_mc_check_mld_get(__VA_ARGS__, batadv_ipv6_mc_check_mld2, batadv_ipv6_mc_check_mld1)(__VA_ARGS__) | ||||||
|  |  | ||||||
|  | static inline int batadv_ip_mc_check_igmp1(struct sk_buff *skb) | ||||||
|  | { | ||||||
|  | 	return ip_mc_check_igmp(skb, NULL); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static inline int batadv_ip_mc_check_igmp2(struct sk_buff *skb, | ||||||
|  | 					   struct sk_buff **skb_trimmed) | ||||||
|  | { | ||||||
|  | 	return ip_mc_check_igmp(skb, skb_trimmed); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #define ip_mc_check_igmp_get(_1, _2, ip_mc_check_igmp_name, ...) ip_mc_check_igmp_name | ||||||
|  | #define ip_mc_check_igmp(...) \ | ||||||
|  | 	ip_mc_check_igmp_get(__VA_ARGS__, batadv_ip_mc_check_igmp2, batadv_ip_mc_check_igmp1)(__VA_ARGS__) | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(5, 1, 0) */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) | ||||||
|  |  | ||||||
|  | #define batadv_softif_slave_add(__dev, __slave_dev, __extack) \ | ||||||
|  | 	batadv_softif_slave_add(__dev, __slave_dev) | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(4, 15, 0) */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) | ||||||
|  |  | ||||||
|  | static inline int batadv_access_ok(int type, const void __user *p, | ||||||
|  | 				   unsigned long size) | ||||||
|  | { | ||||||
|  | 	return access_ok(type, p, size); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #ifdef access_ok | ||||||
|  | #undef access_ok | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define access_ok_get(_1, _2, _3 , access_ok_name, ...) access_ok_name | ||||||
|  | #define access_ok(...) \ | ||||||
|  | 	access_ok_get(__VA_ARGS__, access_ok3, access_ok2)(__VA_ARGS__) | ||||||
|  |  | ||||||
|  | #define access_ok2(addr, size)	batadv_access_ok(VERIFY_WRITE, (addr), (size)) | ||||||
|  | #define access_ok3(type, addr, size)	batadv_access_ok((type), (addr), (size)) | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(5, 0, 0) */ | ||||||
|  |  | ||||||
|  | #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) | ||||||
|  |  | ||||||
|  | #ifndef fallthrough | ||||||
|  | #if __GNUC__ > 7 && !defined(__CHECKER__) | ||||||
|  | # define fallthrough                    __attribute__((__fallthrough__)) | ||||||
|  | #else | ||||||
|  | # define fallthrough                    do {} while (0)  /* fallthrough */ | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #endif /* < KERNEL_VERSION(5, 4, 0) */ | ||||||
|  |  | ||||||
|  | /* <DECLARE_EWMA> */ | ||||||
|  |  | ||||||
|  | #include <linux/version.h> | ||||||
|  | #include_next <linux/average.h> | ||||||
|  |  | ||||||
|  | #include <linux/bug.h> | ||||||
|  |  | ||||||
|  | #ifdef DECLARE_EWMA | ||||||
|  | #undef DECLARE_EWMA | ||||||
|  | #endif /* DECLARE_EWMA */ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Exponentially weighted moving average (EWMA) | ||||||
|  |  * | ||||||
|  |  * This implements a fixed-precision EWMA algorithm, with both the | ||||||
|  |  * precision and fall-off coefficient determined at compile-time | ||||||
|  |  * and built into the generated helper funtions. | ||||||
|  |  * | ||||||
|  |  * The first argument to the macro is the name that will be used | ||||||
|  |  * for the struct and helper functions. | ||||||
|  |  * | ||||||
|  |  * The second argument, the precision, expresses how many bits are | ||||||
|  |  * used for the fractional part of the fixed-precision values. | ||||||
|  |  * | ||||||
|  |  * The third argument, the weight reciprocal, determines how the | ||||||
|  |  * new values will be weighed vs. the old state, new values will | ||||||
|  |  * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note | ||||||
|  |  * that this parameter must be a power of two for efficiency. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #define DECLARE_EWMA(name, _precision, _weight_rcp)			\ | ||||||
|  | 	struct ewma_##name {						\ | ||||||
|  | 		unsigned long internal;					\ | ||||||
|  | 	};								\ | ||||||
|  | 	static inline void ewma_##name##_init(struct ewma_##name *e)	\ | ||||||
|  | 	{								\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_precision));	\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp));	\ | ||||||
|  | 		/*							\ | ||||||
|  | 		 * Even if you want to feed it just 0/1 you should have	\ | ||||||
|  | 		 * some bits for the non-fractional part...		\ | ||||||
|  | 		 */							\ | ||||||
|  | 		BUILD_BUG_ON((_precision) > 30);			\ | ||||||
|  | 		BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp);		\ | ||||||
|  | 		e->internal = 0;					\ | ||||||
|  | 	}								\ | ||||||
|  | 	static inline unsigned long					\ | ||||||
|  | 	ewma_##name##_read(struct ewma_##name *e)			\ | ||||||
|  | 	{								\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_precision));	\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp));	\ | ||||||
|  | 		BUILD_BUG_ON((_precision) > 30);			\ | ||||||
|  | 		BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp);		\ | ||||||
|  | 		return e->internal >> (_precision);			\ | ||||||
|  | 	}								\ | ||||||
|  | 	static inline void ewma_##name##_add(struct ewma_##name *e,	\ | ||||||
|  | 					     unsigned long val)		\ | ||||||
|  | 	{								\ | ||||||
|  | 		unsigned long internal = READ_ONCE(e->internal);	\ | ||||||
|  | 		unsigned long weight_rcp = ilog2(_weight_rcp);		\ | ||||||
|  | 		unsigned long precision = _precision;			\ | ||||||
|  | 									\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_precision));	\ | ||||||
|  | 		BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp));	\ | ||||||
|  | 		BUILD_BUG_ON((_precision) > 30);			\ | ||||||
|  | 		BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp);		\ | ||||||
|  | 									\ | ||||||
|  | 		WRITE_ONCE(e->internal, internal ?			\ | ||||||
|  | 			(((internal << weight_rcp) - internal) +	\ | ||||||
|  | 				(val << precision)) >> weight_rcp :	\ | ||||||
|  | 			(val << precision));				\ | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | /* </DECLARE_EWMA> */ | ||||||
							
								
								
									
										151
									
								
								feeds/ipq40xx/ipq-wifi/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								feeds/ipq40xx/ipq-wifi/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,151 @@ | |||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  | include $(INCLUDE_DIR)/version.mk | ||||||
|  |  | ||||||
|  | PKG_NAME:=ipq-wifi | ||||||
|  | PKG_RELEASE:=1 | ||||||
|  | PKG_FLAGS:=nonshared | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/package.mk | ||||||
|  |  | ||||||
|  | define Build/Prepare | ||||||
|  | 	mkdir -p $(PKG_BUILD_DIR) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define Build/Compile | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | # Use ath10k-bdencoder from https://github.com/qca/qca-swiss-army-knife.git | ||||||
|  | # to generate the board-* files here. | ||||||
|  | # | ||||||
|  | # This is intended to be used on an interim basis until device-specific | ||||||
|  | # board data for new devices is available through the upstream compilation | ||||||
|  | # | ||||||
|  | # Please send a mail with your device-specific board files upstream. | ||||||
|  | # You can find instructions and examples on the linux-wireless wiki: | ||||||
|  | # <https://wireless.wiki.kernel.org/en/users/drivers/ath10k/boardfiles> | ||||||
|  |  | ||||||
|  | ALLWIFIBOARDS:= \ | ||||||
|  | 	8dev_habanero-dvk \ | ||||||
|  | 	aruba_ap-303 \ | ||||||
|  | 	avm_fritzrepeater-1200 \ | ||||||
|  | 	buffalo_wtr-m2133hp \ | ||||||
|  | 	cellc_rtl30vw \ | ||||||
|  | 	devolo_magic-2-wifi-next \ | ||||||
|  | 	dlink_dap2610 \ | ||||||
|  | 	edgecore_ecw5410 \ | ||||||
|  | 	edgecore_ssw2ac2600 \ | ||||||
|  | 	edgecore_oap100 \ | ||||||
|  | 	engenius_eap2200 \ | ||||||
|  | 	engenius_emd1 \ | ||||||
|  | 	engenius_emr3500 \ | ||||||
|  | 	ezviz_cs-w3-wd1200g-eup \ | ||||||
|  | 	glinet_gl-ap1300 \ | ||||||
|  | 	glinet_gl-s1300 \ | ||||||
|  | 	linksys_ea8300 \ | ||||||
|  | 	linksys_mr8300-v0 \ | ||||||
|  | 	luma_wrtq-329acn \ | ||||||
|  | 	mikrotik_hap-ac2 \ | ||||||
|  | 	mikrotik_sxtsq-5-ac \ | ||||||
|  | 	mobipromo_cm520-79f \ | ||||||
|  | 	nec_wg2600hp3 \ | ||||||
|  | 	plasmacloud_pa1200 \ | ||||||
|  | 	plasmacloud_pa2200 \ | ||||||
|  | 	qxwlan_e2600ac \ | ||||||
|  | 	cig_wf610d \ | ||||||
|  | 	wallys_dr40x9 \ | ||||||
|  | 	tp-link_ec420-g1 \ | ||||||
|  | 	udaya-a5-id2 \ | ||||||
|  | 	hfcl_ion4 | ||||||
|  |  | ||||||
|  | ALLWIFIPACKAGES:=$(foreach BOARD,$(ALLWIFIBOARDS),ipq-wifi-$(BOARD)) | ||||||
|  |  | ||||||
|  | define Package/ipq-wifi-default | ||||||
|  |   SUBMENU:=ath10k Board-Specific Overrides | ||||||
|  |   SECTION:=firmware | ||||||
|  |   CATEGORY:=Firmware | ||||||
|  |   DEPENDS:=@(TARGET_ipq40xx||TARGET_ipq806x) | ||||||
|  |   TITLE:=Custom Board | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define ipq-wifi-install-one-to | ||||||
|  |   $(INSTALL_DIR)  $(2)/lib/firmware/ath10k/$(3)/ | ||||||
|  |   $(INSTALL_DATA) $(1) $(2)/lib/firmware/ath10k/$(3)/board-2.bin | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | define ipq-wifi-install-one | ||||||
|  |   $(if $(filter $(suffix $(1)),.QCA4019 .qca4019),\ | ||||||
|  |     $(call ipq-wifi-install-one-to,$(1),$(2),QCA4019/hw1.0),\ | ||||||
|  |   $(if $(filter $(suffix $(1)),.QCA9888 .qca9888),\ | ||||||
|  |     $(call ipq-wifi-install-one-to,$(1),$(2),QCA9888/hw2.0),\ | ||||||
|  |   $(if $(filter $(suffix $(1)),.QCA9984 .qca9984),\ | ||||||
|  |     $(call ipq-wifi-install-one-to,$(1),$(2),QCA9984/hw1.0),\ | ||||||
|  |     $(error Unrecognized board-file suffix '$(suffix $(1))' for '$(1)')\ | ||||||
|  |   ))) | ||||||
|  |  | ||||||
|  | endef | ||||||
|  | # Blank line required at end of above define due to foreach context | ||||||
|  |  | ||||||
|  | define generate-ipq-wifi-package | ||||||
|  |   define Package/ipq-wifi-$(1) | ||||||
|  |     $(call Package/ipq-wifi-default) | ||||||
|  |     TITLE:=board-2.bin Overrides for $(2) | ||||||
|  |     CONFLICTS:=$(PREV_BOARD) | ||||||
|  |   endef | ||||||
|  |  | ||||||
|  |   define Package/ipq-wifi-$(1)/description | ||||||
|  | The $(2) requires board-specific, reference ("cal") data | ||||||
|  | that is not yet present in the upstream wireless firmware distribution. | ||||||
|  |  | ||||||
|  | This package supplies board-2.bin file(s) that, in the interim, | ||||||
|  | overwrite those supplied by the ath10k-firmware-* packages. | ||||||
|  |  | ||||||
|  | This is package is only necessary for the $(2). | ||||||
|  |  | ||||||
|  | Do not install it for any other device! | ||||||
|  |   endef | ||||||
|  |  | ||||||
|  |   define Package/ipq-wifi-$(1)/install-overlay | ||||||
|  |     $$$$(foreach IPQ_WIFI_BOARD_FILE,$$$$(wildcard board-$(1).*),\ | ||||||
|  |       $$$$(call ipq-wifi-install-one,$$$$(IPQ_WIFI_BOARD_FILE),$$(1))) | ||||||
|  |   endef | ||||||
|  |  | ||||||
|  |   PREV_BOARD+=ipq-wifi-$(1) | ||||||
|  | endef | ||||||
|  |  | ||||||
|  | # Add board name to ALLWIFIBOARDS | ||||||
|  | # Place files in this directory as board-<devicename>.<qca4019|qca9888|qca9984> | ||||||
|  | # Add $(eval $(call generate-ipq-wifi-package,<devicename>,<display name>)) | ||||||
|  |  | ||||||
|  | $(eval $(call generate-ipq-wifi-package,8dev_habanero-dvk,8devices Habanero DVK)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,aruba_ap-303,Aruba AP-303)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,avm_fritzrepeater-1200,AVM FRITZRepeater 1200)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,buffalo_wtr-m2133hp,Buffalo WTR-M2133HP)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,cellc_rtl30vw, Cell C RTL30VW)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,devolo_magic-2-wifi-next,devolo Magic 2 WiFi next)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,dlink_dap2610,D-Link DAP-2610)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,edgecore_ecw5410,Edgecore ECW5410)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,edgecore_ssw2ac2600,Edgecore SSW2AC2600)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,edgecore_oap100,Edgecore OAP100)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,engenius_eap2200,EnGenius EAP2200)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,engenius_emd1,EnGenius EMD1)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,engenius_emr3500,EnGenius EMR3500)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,ezviz_cs-w3-wd1200g-eup,EZVIZ CS-W3-WD1200G EUP)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,glinet_gl-ap1300,GL.iNet GL-AP1300)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,glinet_gl-s1300,GL.iNet GL-S1300)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,linksys_ea8300,Linksys EA8300)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,linksys_mr8300-v0,Linksys MR8300)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,luma_wrtq-329acn,Luma WRTQ-329ACN)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,mikrotik_hap-ac2,Mikrotik hAP ac2)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,mikrotik_sxtsq-5-ac,MikroTik SXTsq 5 ac)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,mobipromo_cm520-79f,MobiPromo CM520-79F)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,nec_wg2600hp3,NEC Platforms WG2600HP3)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,plasmacloud_pa1200,Plasma Cloud PA1200)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,plasmacloud_pa2200,Plasma Cloud PA2200)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,qxwlan_e2600ac,Qxwlan E2600AC)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,cig_wf610d,CIG WF_610D)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,tp-link_ec420-g1,tp-link EC420-G1)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,wallys_dr40x9,Wallys DR40X9)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,hfcl_ion4,HFCL ION4)) | ||||||
|  | $(eval $(call generate-ipq-wifi-package,udaya-a5-id2,udaya A5 ID2)) | ||||||
|  |  | ||||||
|  | $(foreach PACKAGE,$(ALLWIFIPACKAGES),$(eval $(call BuildPackage,$(PACKAGE)))) | ||||||
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-8dev_habanero-dvk.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-8dev_habanero-dvk.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-aruba_ap-303.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-aruba_ap-303.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-avm_fritzrepeater-1200.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-avm_fritzrepeater-1200.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-buffalo_wtr-m2133hp.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-buffalo_wtr-m2133hp.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-buffalo_wtr-m2133hp.qca9984
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-buffalo_wtr-m2133hp.qca9984
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-cellc_rtl30vw.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-cellc_rtl30vw.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-cig_wf610d.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-cig_wf610d.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-devolo_magic-2-wifi-next.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-devolo_magic-2-wifi-next.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-dlink_dap2610.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-dlink_dap2610.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_ecw5410.qca9984
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_ecw5410.qca9984
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_oap100.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_oap100.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_ssw2ac2600.qca9984
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-edgecore_ssw2ac2600.qca9984
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_eap2200.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_eap2200.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_eap2200.qca9888
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_eap2200.qca9888
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_emd1.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_emd1.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_emr3500.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-engenius_emr3500.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-ezviz_cs-w3-wd1200g-eup.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-ezviz_cs-w3-wd1200g-eup.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-glinet_gl-ap1300.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-glinet_gl-ap1300.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-glinet_gl-s1300.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-glinet_gl-s1300.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_ea8300.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_ea8300.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_ea8300.qca9888
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_ea8300.qca9888
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_mr8300-v0.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_mr8300-v0.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_mr8300-v0.qca9888
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-linksys_mr8300-v0.qca9888
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-luma_wrtq-329acn.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-luma_wrtq-329acn.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mikrotik_hap-ac2.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mikrotik_hap-ac2.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mikrotik_sxtsq-5-ac.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mikrotik_sxtsq-5-ac.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mobipromo_cm520-79f.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-mobipromo_cm520-79f.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-nec_wg2600hp3.qca9984
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-nec_wg2600hp3.qca9984
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa1200.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa1200.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa2200.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa2200.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa2200.qca9888
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-plasmacloud_pa2200.qca9888
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-qxwlan_e2600ac.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-qxwlan_e2600ac.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-tp-link_ec420-g1.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-tp-link_ec420-g1.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-tp-link_ec420-g1.qca9984
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-tp-link_ec420-g1.qca9984
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-udaya-a5-id2.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-udaya-a5-id2.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-wallys_dr40x9.qca4019
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								feeds/ipq40xx/ipq-wifi/board-wallys_dr40x9.qca4019
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										31
									
								
								feeds/ipq40xx/ipq40xx/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								feeds/ipq40xx/ipq40xx/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | include $(TOPDIR)/rules.mk | ||||||
|  |  | ||||||
|  | ARCH:=arm | ||||||
|  | BOARD:=ipq40xx | ||||||
|  | BOARDNAME:=Qualcomm Atheros IPQ40XX | ||||||
|  | FEATURES:=squashfs fpu ramdisk nand | ||||||
|  | CPU_TYPE:=cortex-a7 | ||||||
|  | CPU_SUBTYPE:=neon-vfpv4 | ||||||
|  | SUBTARGETS:=generic mikrotik | ||||||
|  |  | ||||||
|  | KERNEL_PATCHVER:=5.4 | ||||||
|  | KERNEL_TESTING_PATCHVER:=5.4 | ||||||
|  | DEVICE_TYPE:=qsdk | ||||||
|  |  | ||||||
|  | KERNELNAME:=zImage Image dtbs | ||||||
|  |  | ||||||
|  | GENERIC_BACKPORT_DIR := ${CURDIR}/backport-$(KERNEL_PATCHVER) | ||||||
|  | GENERIC_PATCH_DIR := ${CURDIR}/pending-$(KERNEL_PATCHVER) | ||||||
|  | GENERIC_HACK_DIR := ${CURDIR}/hack-$(KERNEL_PATCHVER) | ||||||
|  | GENERIC_FILES_DIR :=  | ||||||
|  | GENERIC_LINUX_CONFIG:=${CURDIR}/config-$(KERNEL_PATCHVER)-ipq40xx | ||||||
|  |  | ||||||
|  | include $(INCLUDE_DIR)/target.mk | ||||||
|  | DEFAULT_PACKAGES += \ | ||||||
|  | 	kmod-usb-dwc3-qcom \ | ||||||
|  | 	kmod-leds-gpio kmod-gpio-button-hotplug swconfig \ | ||||||
|  | 	kmod-ath10k-ct wpad-basic-wolfssl \ | ||||||
|  | 	kmod-usb3 kmod-usb-dwc3 ath10k-firmware-qca4019-ct \ | ||||||
|  | 	uboot-envtools | ||||||
|  |  | ||||||
|  | $(eval $(call BuildTarget)) | ||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | From 13b1ecc3401653a355798eb1dee10cc1608202f4 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Felix Fietkau <nbd@nbd.name> | ||||||
|  | Date: Mon, 18 Jan 2016 12:27:49 +0100 | ||||||
|  | Subject: [PATCH 33/34] Kbuild: don't hardcode path to awk in | ||||||
|  |  scripts/ld-version.sh | ||||||
|  |  | ||||||
|  | On some systems /usr/bin/awk does not exist, or is broken. Find it via | ||||||
|  | $PATH instead. | ||||||
|  |  | ||||||
|  | Signed-off-by: Felix Fietkau <nbd@nbd.name> | ||||||
|  | --- | ||||||
|  |  scripts/ld-version.sh | 4 +++- | ||||||
|  |  1 file changed, 3 insertions(+), 1 deletion(-) | ||||||
|  |  | ||||||
|  | --- a/scripts/ld-version.sh | ||||||
|  | +++ b/scripts/ld-version.sh | ||||||
|  | @@ -1,6 +1,7 @@ | ||||||
|  | -#!/usr/bin/awk -f | ||||||
|  | +#!/bin/sh | ||||||
|  |  # SPDX-License-Identifier: GPL-2.0 | ||||||
|  |  # extract linker version number from stdin and turn into single number | ||||||
|  | +exec awk ' | ||||||
|  |  	{ | ||||||
|  |  	gsub(".*\\)", ""); | ||||||
|  |  	gsub(".*version ", ""); | ||||||
|  | @@ -9,3 +10,4 @@ | ||||||
|  |  	print a[1]*100000000 + a[2]*1000000 + a[3]*10000; | ||||||
|  |  	exit | ||||||
|  |  	} | ||||||
|  | +' | ||||||
| @@ -0,0 +1,21 @@ | |||||||
|  | From 173019b66dcc9d68ad9333aa744dad1e369b5aa8 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Felix Fietkau <nbd@nbd.name> | ||||||
|  | Date: Sun, 9 Jul 2017 00:26:53 +0200 | ||||||
|  | Subject: [PATCH 34/34] kernel: add compile fix for linux 4.9 on x86 | ||||||
|  |  | ||||||
|  | Signed-off-by: Felix Fietkau <nbd@nbd.name> | ||||||
|  | --- | ||||||
|  |  Makefile | 4 ++-- | ||||||
|  |  1 file changed, 2 insertions(+), 2 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/Makefile | ||||||
|  | +++ b/Makefile | ||||||
|  | @@ -493,7 +493,7 @@ KBUILD_LDFLAGS := | ||||||
|  |  GCC_PLUGINS_CFLAGS := | ||||||
|  |  CLANG_FLAGS := | ||||||
|  |   | ||||||
|  | -export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC | ||||||
|  | +export ARCH SRCARCH SUBARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC | ||||||
|  |  export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL | ||||||
|  |  export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX | ||||||
|  |  export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ | ||||||
| @@ -0,0 +1,53 @@ | |||||||
|  | From afa0459daa7b08c7b2c879705b69d39b734a11d0 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Masahiro Yamada <yamada.masahiro@socionext.com> | ||||||
|  | Date: Fri, 15 Nov 2019 02:42:21 +0900 | ||||||
|  | Subject: [PATCH] modpost: add a helper to get data pointed by a symbol | ||||||
|  |  | ||||||
|  | When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not | ||||||
|  | an absolute value, but the address to the CRC data embedded in the | ||||||
|  | .rodata section. | ||||||
|  |  | ||||||
|  | Getting the data pointed by the symbol value is somewhat complex. | ||||||
|  | Split it out into a new helper, sym_get_data(). | ||||||
|  |  | ||||||
|  | I will reuse it to refactor namespace_from_kstrtabns() in the next | ||||||
|  | commit. | ||||||
|  |  | ||||||
|  | Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> | ||||||
|  | --- | ||||||
|  |  scripts/mod/modpost.c | 17 +++++++++++++---- | ||||||
|  |  1 file changed, 13 insertions(+), 4 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/scripts/mod/modpost.c | ||||||
|  | +++ b/scripts/mod/modpost.c | ||||||
|  | @@ -312,6 +312,18 @@ static const char *sec_name(struct elf_i | ||||||
|  |  	return sech_name(elf, &elf->sechdrs[secindex]); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) | ||||||
|  | +{ | ||||||
|  | +	Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx]; | ||||||
|  | +	unsigned long offset; | ||||||
|  | + | ||||||
|  | +	offset = sym->st_value; | ||||||
|  | +	if (info->hdr->e_type != ET_REL) | ||||||
|  | +		offset -= sechdr->sh_addr; | ||||||
|  | + | ||||||
|  | +	return (void *)info->hdr + sechdr->sh_offset + offset; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  |  #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) | ||||||
|  |   | ||||||
|  |  static enum export export_from_secname(struct elf_info *elf, unsigned int sec) | ||||||
|  | @@ -701,10 +713,7 @@ static void handle_modversions(struct mo | ||||||
|  |  			unsigned int *crcp; | ||||||
|  |   | ||||||
|  |  			/* symbol points to the CRC in the ELF object */ | ||||||
|  | -			crcp = (void *)info->hdr + sym->st_value + | ||||||
|  | -			       info->sechdrs[sym->st_shndx].sh_offset - | ||||||
|  | -			       (info->hdr->e_type != ET_REL ? | ||||||
|  | -				info->sechdrs[sym->st_shndx].sh_addr : 0); | ||||||
|  | +			crcp = sym_get_data(info, sym); | ||||||
|  |  			crc = TO_NATIVE(*crcp); | ||||||
|  |  		} | ||||||
|  |  		sym_update_crc(symname + strlen("__crc_"), mod, crc, | ||||||
| @@ -0,0 +1,62 @@ | |||||||
|  | From e84f9fbbece1585f45a03ccc11eeabe121cadc1b Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Masahiro Yamada <yamada.masahiro@socionext.com> | ||||||
|  | Date: Fri, 15 Nov 2019 02:42:22 +0900 | ||||||
|  | Subject: [PATCH] modpost: refactor namespace_from_kstrtabns() to not hard-code | ||||||
|  |  section name | ||||||
|  |  | ||||||
|  | Currently, namespace_from_kstrtabns() relies on the fact that | ||||||
|  | namespace strings are recorded in the __ksymtab_strings section. | ||||||
|  | Actually, it is coded in include/linux/export.h, but modpost does | ||||||
|  | not need to hard-code the section name. | ||||||
|  |  | ||||||
|  | Elf_Sym::st_shndx holds the index of the relevant section. Using it is | ||||||
|  | a more portable way to get the namespace string. | ||||||
|  |  | ||||||
|  | Make namespace_from_kstrtabns() simply call sym_get_data(), and delete | ||||||
|  | the info->ksymtab_strings . | ||||||
|  |  | ||||||
|  | While I was here, I added more 'const' qualifiers to pointers. | ||||||
|  |  | ||||||
|  | Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> | ||||||
|  | --- | ||||||
|  |  scripts/mod/modpost.c | 10 +++------- | ||||||
|  |  scripts/mod/modpost.h |  1 - | ||||||
|  |  2 files changed, 3 insertions(+), 8 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/scripts/mod/modpost.c | ||||||
|  | +++ b/scripts/mod/modpost.c | ||||||
|  | @@ -360,10 +360,10 @@ static enum export export_from_sec(struc | ||||||
|  |  		return export_unknown; | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | -static const char *namespace_from_kstrtabns(struct elf_info *info, | ||||||
|  | -					    Elf_Sym *kstrtabns) | ||||||
|  | +static const char *namespace_from_kstrtabns(const struct elf_info *info, | ||||||
|  | +					    const Elf_Sym *sym) | ||||||
|  |  { | ||||||
|  | -	char *value = info->ksymtab_strings + kstrtabns->st_value; | ||||||
|  | +	const char *value = sym_get_data(info, sym); | ||||||
|  |  	return value[0] ? value : NULL; | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | @@ -605,10 +605,6 @@ static int parse_elf(struct elf_info *in | ||||||
|  |  			info->export_unused_gpl_sec = i; | ||||||
|  |  		else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | ||||||
|  |  			info->export_gpl_future_sec = i; | ||||||
|  | -		else if (strcmp(secname, "__ksymtab_strings") == 0) | ||||||
|  | -			info->ksymtab_strings = (void *)hdr + | ||||||
|  | -						sechdrs[i].sh_offset - | ||||||
|  | -						sechdrs[i].sh_addr; | ||||||
|  |   | ||||||
|  |  		if (sechdrs[i].sh_type == SHT_SYMTAB) { | ||||||
|  |  			unsigned int sh_link_idx; | ||||||
|  | --- a/scripts/mod/modpost.h | ||||||
|  | +++ b/scripts/mod/modpost.h | ||||||
|  | @@ -143,7 +143,6 @@ struct elf_info { | ||||||
|  |  	Elf_Section  export_gpl_sec; | ||||||
|  |  	Elf_Section  export_unused_gpl_sec; | ||||||
|  |  	Elf_Section  export_gpl_future_sec; | ||||||
|  | -	char	     *ksymtab_strings; | ||||||
|  |  	char         *strtab; | ||||||
|  |  	char	     *modinfo; | ||||||
|  |  	unsigned int modinfo_len; | ||||||
| @@ -0,0 +1,176 @@ | |||||||
|  | From: Robin Murphy <robin.murphy@arm.com> | ||||||
|  | Date: Wed, 15 Jan 2020 16:42:39 +0000 | ||||||
|  | Subject: [PATCH] arm64: Implement optimised checksum routine | ||||||
|  |  | ||||||
|  | Apparently there exist certain workloads which rely heavily on software | ||||||
|  | checksumming, for which the generic do_csum() implementation becomes a | ||||||
|  | significant bottleneck. Therefore let's give arm64 its own optimised | ||||||
|  | version - for ease of maintenance this foregoes assembly or intrisics, | ||||||
|  | and is thus not actually arm64-specific, but does rely heavily on C | ||||||
|  | idioms that translate well to the A64 ISA and the typical load/store | ||||||
|  | capabilities of most ARMv8 CPU cores. | ||||||
|  |  | ||||||
|  | The resulting increase in checksum throughput scales nicely with buffer | ||||||
|  | size, tending towards 4x for a small in-order core (Cortex-A53), and up | ||||||
|  | to 6x or more for an aggressive big core (Ampere eMAG). | ||||||
|  |  | ||||||
|  | Reported-by: Lingyan Huang <huanglingyan2@huawei.com> | ||||||
|  | Tested-by: Lingyan Huang <huanglingyan2@huawei.com> | ||||||
|  | Signed-off-by: Robin Murphy <robin.murphy@arm.com> | ||||||
|  | Signed-off-by: Will Deacon <will@kernel.org> | ||||||
|  | --- | ||||||
|  |  create mode 100644 arch/arm64/lib/csum.c | ||||||
|  |  | ||||||
|  | --- a/arch/arm64/include/asm/checksum.h | ||||||
|  | +++ b/arch/arm64/include/asm/checksum.h | ||||||
|  | @@ -36,6 +36,9 @@ static inline __sum16 ip_fast_csum(const | ||||||
|  |  } | ||||||
|  |  #define ip_fast_csum ip_fast_csum | ||||||
|  |   | ||||||
|  | +extern unsigned int do_csum(const unsigned char *buff, int len); | ||||||
|  | +#define do_csum do_csum | ||||||
|  | + | ||||||
|  |  #include <asm-generic/checksum.h> | ||||||
|  |   | ||||||
|  |  #endif	/* __ASM_CHECKSUM_H */ | ||||||
|  | --- a/arch/arm64/lib/Makefile | ||||||
|  | +++ b/arch/arm64/lib/Makefile | ||||||
|  | @@ -1,9 +1,9 @@ | ||||||
|  |  # SPDX-License-Identifier: GPL-2.0 | ||||||
|  |  lib-y		:= clear_user.o delay.o copy_from_user.o		\ | ||||||
|  |  		   copy_to_user.o copy_in_user.o copy_page.o		\ | ||||||
|  | -		   clear_page.o memchr.o memcpy.o memmove.o memset.o	\ | ||||||
|  | -		   memcmp.o strcmp.o strncmp.o strlen.o strnlen.o	\ | ||||||
|  | -		   strchr.o strrchr.o tishift.o | ||||||
|  | +		   clear_page.o csum.o memchr.o memcpy.o memmove.o	\ | ||||||
|  | +		   memset.o memcmp.o strcmp.o strncmp.o strlen.o	\ | ||||||
|  | +		   strnlen.o strchr.o strrchr.o tishift.o | ||||||
|  |   | ||||||
|  |  ifeq ($(CONFIG_KERNEL_MODE_NEON), y) | ||||||
|  |  obj-$(CONFIG_XOR_BLOCKS)	+= xor-neon.o | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/arch/arm64/lib/csum.c | ||||||
|  | @@ -0,0 +1,123 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0-only | ||||||
|  | +// Copyright (C) 2019-2020 Arm Ltd. | ||||||
|  | + | ||||||
|  | +#include <linux/compiler.h> | ||||||
|  | +#include <linux/kasan-checks.h> | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | + | ||||||
|  | +#include <net/checksum.h> | ||||||
|  | + | ||||||
|  | +/* Looks dumb, but generates nice-ish code */ | ||||||
|  | +static u64 accumulate(u64 sum, u64 data) | ||||||
|  | +{ | ||||||
|  | +	__uint128_t tmp = (__uint128_t)sum + data; | ||||||
|  | +	return tmp + (tmp >> 64); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +unsigned int do_csum(const unsigned char *buff, int len) | ||||||
|  | +{ | ||||||
|  | +	unsigned int offset, shift, sum; | ||||||
|  | +	const u64 *ptr; | ||||||
|  | +	u64 data, sum64 = 0; | ||||||
|  | + | ||||||
|  | +	offset = (unsigned long)buff & 7; | ||||||
|  | +	/* | ||||||
|  | +	 * This is to all intents and purposes safe, since rounding down cannot | ||||||
|  | +	 * result in a different page or cache line being accessed, and @buff | ||||||
|  | +	 * should absolutely not be pointing to anything read-sensitive. We do, | ||||||
|  | +	 * however, have to be careful not to piss off KASAN, which means using | ||||||
|  | +	 * unchecked reads to accommodate the head and tail, for which we'll | ||||||
|  | +	 * compensate with an explicit check up-front. | ||||||
|  | +	 */ | ||||||
|  | +	kasan_check_read(buff, len); | ||||||
|  | +	ptr = (u64 *)(buff - offset); | ||||||
|  | +	len = len + offset - 8; | ||||||
|  | + | ||||||
|  | +	/* | ||||||
|  | +	 * Head: zero out any excess leading bytes. Shifting back by the same | ||||||
|  | +	 * amount should be at least as fast as any other way of handling the | ||||||
|  | +	 * odd/even alignment, and means we can ignore it until the very end. | ||||||
|  | +	 */ | ||||||
|  | +	shift = offset * 8; | ||||||
|  | +	data = READ_ONCE_NOCHECK(*ptr++); | ||||||
|  | +#ifdef __LITTLE_ENDIAN | ||||||
|  | +	data = (data >> shift) << shift; | ||||||
|  | +#else | ||||||
|  | +	data = (data << shift) >> shift; | ||||||
|  | +#endif | ||||||
|  | + | ||||||
|  | +	/* | ||||||
|  | +	 * Body: straightforward aligned loads from here on (the paired loads | ||||||
|  | +	 * underlying the quadword type still only need dword alignment). The | ||||||
|  | +	 * main loop strictly excludes the tail, so the second loop will always | ||||||
|  | +	 * run at least once. | ||||||
|  | +	 */ | ||||||
|  | +	while (unlikely(len > 64)) { | ||||||
|  | +		__uint128_t tmp1, tmp2, tmp3, tmp4; | ||||||
|  | + | ||||||
|  | +		tmp1 = READ_ONCE_NOCHECK(*(__uint128_t *)ptr); | ||||||
|  | +		tmp2 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 2)); | ||||||
|  | +		tmp3 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 4)); | ||||||
|  | +		tmp4 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 6)); | ||||||
|  | + | ||||||
|  | +		len -= 64; | ||||||
|  | +		ptr += 8; | ||||||
|  | + | ||||||
|  | +		/* This is the "don't dump the carry flag into a GPR" idiom */ | ||||||
|  | +		tmp1 += (tmp1 >> 64) | (tmp1 << 64); | ||||||
|  | +		tmp2 += (tmp2 >> 64) | (tmp2 << 64); | ||||||
|  | +		tmp3 += (tmp3 >> 64) | (tmp3 << 64); | ||||||
|  | +		tmp4 += (tmp4 >> 64) | (tmp4 << 64); | ||||||
|  | +		tmp1 = ((tmp1 >> 64) << 64) | (tmp2 >> 64); | ||||||
|  | +		tmp1 += (tmp1 >> 64) | (tmp1 << 64); | ||||||
|  | +		tmp3 = ((tmp3 >> 64) << 64) | (tmp4 >> 64); | ||||||
|  | +		tmp3 += (tmp3 >> 64) | (tmp3 << 64); | ||||||
|  | +		tmp1 = ((tmp1 >> 64) << 64) | (tmp3 >> 64); | ||||||
|  | +		tmp1 += (tmp1 >> 64) | (tmp1 << 64); | ||||||
|  | +		tmp1 = ((tmp1 >> 64) << 64) | sum64; | ||||||
|  | +		tmp1 += (tmp1 >> 64) | (tmp1 << 64); | ||||||
|  | +		sum64 = tmp1 >> 64; | ||||||
|  | +	} | ||||||
|  | +	while (len > 8) { | ||||||
|  | +		__uint128_t tmp; | ||||||
|  | + | ||||||
|  | +		sum64 = accumulate(sum64, data); | ||||||
|  | +		tmp = READ_ONCE_NOCHECK(*(__uint128_t *)ptr); | ||||||
|  | + | ||||||
|  | +		len -= 16; | ||||||
|  | +		ptr += 2; | ||||||
|  | + | ||||||
|  | +#ifdef __LITTLE_ENDIAN | ||||||
|  | +		data = tmp >> 64; | ||||||
|  | +		sum64 = accumulate(sum64, tmp); | ||||||
|  | +#else | ||||||
|  | +		data = tmp; | ||||||
|  | +		sum64 = accumulate(sum64, tmp >> 64); | ||||||
|  | +#endif | ||||||
|  | +	} | ||||||
|  | +	if (len > 0) { | ||||||
|  | +		sum64 = accumulate(sum64, data); | ||||||
|  | +		data = READ_ONCE_NOCHECK(*ptr); | ||||||
|  | +		len -= 8; | ||||||
|  | +	} | ||||||
|  | +	/* | ||||||
|  | +	 * Tail: zero any over-read bytes similarly to the head, again | ||||||
|  | +	 * preserving odd/even alignment. | ||||||
|  | +	 */ | ||||||
|  | +	shift = len * -8; | ||||||
|  | +#ifdef __LITTLE_ENDIAN | ||||||
|  | +	data = (data << shift) >> shift; | ||||||
|  | +#else | ||||||
|  | +	data = (data >> shift) << shift; | ||||||
|  | +#endif | ||||||
|  | +	sum64 = accumulate(sum64, data); | ||||||
|  | + | ||||||
|  | +	/* Finally, folding */ | ||||||
|  | +	sum64 += (sum64 >> 32) | (sum64 << 32); | ||||||
|  | +	sum = sum64 >> 32; | ||||||
|  | +	sum += (sum >> 16) | (sum << 16); | ||||||
|  | +	if (offset & 1) | ||||||
|  | +		return (u16)swab32(sum); | ||||||
|  | + | ||||||
|  | +	return sum >> 16; | ||||||
|  | +} | ||||||
| @@ -0,0 +1,28 @@ | |||||||
|  | From: Robin Murphy <robin.murphy@arm.com> | ||||||
|  | Date: Fri, 17 Jan 2020 15:48:39 +0000 | ||||||
|  | Subject: [PATCH] arm64: csum: Fix pathological zero-length calls | ||||||
|  |  | ||||||
|  | In validating the checksumming results of the new routine, I sadly | ||||||
|  | neglected to test its not-checksumming results. Thus it slipped through | ||||||
|  | that the one case where @buff is already dword-aligned and @len = 0 | ||||||
|  | manages to defeat the tail-masking logic and behave as if @len = 8. | ||||||
|  | For a zero length it doesn't make much sense to deference @buff anyway, | ||||||
|  | so just add an early return (which has essentially zero impact on | ||||||
|  | performance). | ||||||
|  |  | ||||||
|  | Signed-off-by: Robin Murphy <robin.murphy@arm.com> | ||||||
|  | Signed-off-by: Will Deacon <will@kernel.org> | ||||||
|  | --- | ||||||
|  |  | ||||||
|  | --- a/arch/arm64/lib/csum.c | ||||||
|  | +++ b/arch/arm64/lib/csum.c | ||||||
|  | @@ -20,6 +20,9 @@ unsigned int do_csum(const unsigned char | ||||||
|  |  	const u64 *ptr; | ||||||
|  |  	u64 data, sum64 = 0; | ||||||
|  |   | ||||||
|  | +	if (unlikely(len == 0)) | ||||||
|  | +		return 0; | ||||||
|  | + | ||||||
|  |  	offset = (unsigned long)buff & 7; | ||||||
|  |  	/* | ||||||
|  |  	 * This is to all intents and purposes safe, since rounding down cannot | ||||||
| @@ -0,0 +1,112 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:07 +0100 | ||||||
|  | Subject: [PATCH] crypto: lib - tidy up lib/crypto Kconfig and Makefile | ||||||
|  |  | ||||||
|  | commit 746b2e024c67aa605ac12d135cd7085a49cf9dc4 upstream. | ||||||
|  |  | ||||||
|  | In preparation of introducing a set of crypto library interfaces, tidy | ||||||
|  | up the Makefile and split off the Kconfig symbols into a separate file. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  crypto/Kconfig      | 13 +------------ | ||||||
|  |  lib/crypto/Kconfig  | 15 +++++++++++++++ | ||||||
|  |  lib/crypto/Makefile | 16 ++++++++-------- | ||||||
|  |  3 files changed, 24 insertions(+), 20 deletions(-) | ||||||
|  |  create mode 100644 lib/crypto/Kconfig | ||||||
|  |  | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -878,9 +878,6 @@ config CRYPTO_SHA1_PPC_SPE | ||||||
|  |  	  SHA-1 secure hash standard (DFIPS 180-4) implemented | ||||||
|  |  	  using powerpc SPE SIMD instruction set. | ||||||
|  |   | ||||||
|  | -config CRYPTO_LIB_SHA256 | ||||||
|  | -	tristate | ||||||
|  | - | ||||||
|  |  config CRYPTO_SHA256 | ||||||
|  |  	tristate "SHA224 and SHA256 digest algorithm" | ||||||
|  |  	select CRYPTO_HASH | ||||||
|  | @@ -1019,9 +1016,6 @@ config CRYPTO_GHASH_CLMUL_NI_INTEL | ||||||
|  |   | ||||||
|  |  comment "Ciphers" | ||||||
|  |   | ||||||
|  | -config CRYPTO_LIB_AES | ||||||
|  | -	tristate | ||||||
|  | - | ||||||
|  |  config CRYPTO_AES | ||||||
|  |  	tristate "AES cipher algorithms" | ||||||
|  |  	select CRYPTO_ALGAPI | ||||||
|  | @@ -1150,9 +1144,6 @@ config CRYPTO_ANUBIS | ||||||
|  |  	  <https://www.cosic.esat.kuleuven.be/nessie/reports/> | ||||||
|  |  	  <http://www.larc.usp.br/~pbarreto/AnubisPage.html> | ||||||
|  |   | ||||||
|  | -config CRYPTO_LIB_ARC4 | ||||||
|  | -	tristate | ||||||
|  | - | ||||||
|  |  config CRYPTO_ARC4 | ||||||
|  |  	tristate "ARC4 cipher algorithm" | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  | @@ -1339,9 +1330,6 @@ config CRYPTO_CAST6_AVX_X86_64 | ||||||
|  |  	  This module provides the Cast6 cipher algorithm that processes | ||||||
|  |  	  eight blocks parallel using the AVX instruction set. | ||||||
|  |   | ||||||
|  | -config CRYPTO_LIB_DES | ||||||
|  | -	tristate | ||||||
|  | - | ||||||
|  |  config CRYPTO_DES | ||||||
|  |  	tristate "DES and Triple DES EDE cipher algorithms" | ||||||
|  |  	select CRYPTO_ALGAPI | ||||||
|  | @@ -1845,6 +1833,7 @@ config CRYPTO_STATS | ||||||
|  |  config CRYPTO_HASH_INFO | ||||||
|  |  	bool | ||||||
|  |   | ||||||
|  | +source "lib/crypto/Kconfig" | ||||||
|  |  source "drivers/crypto/Kconfig" | ||||||
|  |  source "crypto/asymmetric_keys/Kconfig" | ||||||
|  |  source "certs/Kconfig" | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/lib/crypto/Kconfig | ||||||
|  | @@ -0,0 +1,15 @@ | ||||||
|  | +# SPDX-License-Identifier: GPL-2.0 | ||||||
|  | + | ||||||
|  | +comment "Crypto library routines" | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_AES | ||||||
|  | +	tristate | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_ARC4 | ||||||
|  | +	tristate | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_DES | ||||||
|  | +	tristate | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_SHA256 | ||||||
|  | +	tristate | ||||||
|  | --- a/lib/crypto/Makefile | ||||||
|  | +++ b/lib/crypto/Makefile | ||||||
|  | @@ -1,13 +1,13 @@ | ||||||
|  |  # SPDX-License-Identifier: GPL-2.0 | ||||||
|  |   | ||||||
|  | -obj-$(CONFIG_CRYPTO_LIB_AES) += libaes.o | ||||||
|  | -libaes-y := aes.o | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_AES)			+= libaes.o | ||||||
|  | +libaes-y					:= aes.o | ||||||
|  |   | ||||||
|  | -obj-$(CONFIG_CRYPTO_LIB_ARC4) += libarc4.o | ||||||
|  | -libarc4-y := arc4.o | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_ARC4)			+= libarc4.o | ||||||
|  | +libarc4-y					:= arc4.o | ||||||
|  |   | ||||||
|  | -obj-$(CONFIG_CRYPTO_LIB_DES) += libdes.o | ||||||
|  | -libdes-y := des.o | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_DES)			+= libdes.o | ||||||
|  | +libdes-y					:= des.o | ||||||
|  |   | ||||||
|  | -obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o | ||||||
|  | -libsha256-y := sha256.o | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_SHA256)			+= libsha256.o | ||||||
|  | +libsha256-y					:= sha256.o | ||||||
| @@ -0,0 +1,668 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:08 +0100 | ||||||
|  | Subject: [PATCH] crypto: chacha - move existing library code into lib/crypto | ||||||
|  |  | ||||||
|  | commit 5fb8ef25803ef33e2eb60b626435828b937bed75 upstream. | ||||||
|  |  | ||||||
|  | Currently, our generic ChaCha implementation consists of a permute | ||||||
|  | function in lib/chacha.c that operates on the 64-byte ChaCha state | ||||||
|  | directly [and which is always included into the core kernel since it | ||||||
|  | is used by the /dev/random driver], and the crypto API plumbing to | ||||||
|  | expose it as a skcipher. | ||||||
|  |  | ||||||
|  | In order to support in-kernel users that need the ChaCha streamcipher | ||||||
|  | but have no need [or tolerance] for going through the abstractions of | ||||||
|  | the crypto API, let's expose the streamcipher bits via a library API | ||||||
|  | as well, in a way that permits the implementation to be superseded by | ||||||
|  | an architecture specific one if provided. | ||||||
|  |  | ||||||
|  | So move the streamcipher code into a separate module in lib/crypto, | ||||||
|  | and expose the init() and crypt() routines to users of the library. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm/crypto/chacha-neon-glue.c   |  2 +- | ||||||
|  |  arch/arm64/crypto/chacha-neon-glue.c |  2 +- | ||||||
|  |  arch/x86/crypto/chacha_glue.c        |  2 +- | ||||||
|  |  crypto/Kconfig                       |  1 + | ||||||
|  |  crypto/chacha_generic.c              | 60 ++-------------------- | ||||||
|  |  include/crypto/chacha.h              | 77 ++++++++++++++++++++++------ | ||||||
|  |  include/crypto/internal/chacha.h     | 53 +++++++++++++++++++ | ||||||
|  |  lib/Makefile                         |  3 +- | ||||||
|  |  lib/crypto/Kconfig                   | 26 ++++++++++ | ||||||
|  |  lib/crypto/Makefile                  |  4 ++ | ||||||
|  |  lib/{ => crypto}/chacha.c            | 20 ++++---- | ||||||
|  |  lib/crypto/libchacha.c               | 35 +++++++++++++ | ||||||
|  |  12 files changed, 199 insertions(+), 86 deletions(-) | ||||||
|  |  create mode 100644 include/crypto/internal/chacha.h | ||||||
|  |  rename lib/{ => crypto}/chacha.c (88%) | ||||||
|  |  create mode 100644 lib/crypto/libchacha.c | ||||||
|  |  | ||||||
|  | --- a/arch/arm/crypto/chacha-neon-glue.c | ||||||
|  | +++ b/arch/arm/crypto/chacha-neon-glue.c | ||||||
|  | @@ -20,7 +20,7 @@ | ||||||
|  |   */ | ||||||
|  |   | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  | -#include <crypto/chacha.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  | --- a/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | +++ b/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | @@ -20,7 +20,7 @@ | ||||||
|  |   */ | ||||||
|  |   | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  | -#include <crypto/chacha.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  | --- a/arch/x86/crypto/chacha_glue.c | ||||||
|  | +++ b/arch/x86/crypto/chacha_glue.c | ||||||
|  | @@ -7,7 +7,7 @@ | ||||||
|  |   */ | ||||||
|  |   | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  | -#include <crypto/chacha.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -1393,6 +1393,7 @@ config CRYPTO_SALSA20 | ||||||
|  |   | ||||||
|  |  config CRYPTO_CHACHA20 | ||||||
|  |  	tristate "ChaCha stream cipher algorithms" | ||||||
|  | +	select CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  |  	help | ||||||
|  |  	  The ChaCha20, XChaCha20, and XChaCha12 stream cipher algorithms. | ||||||
|  | --- a/crypto/chacha_generic.c | ||||||
|  | +++ b/crypto/chacha_generic.c | ||||||
|  | @@ -8,29 +8,10 @@ | ||||||
|  |   | ||||||
|  |  #include <asm/unaligned.h> | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  | -#include <crypto/chacha.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  |  #include <linux/module.h> | ||||||
|  |   | ||||||
|  | -static void chacha_docrypt(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | -			   unsigned int bytes, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	/* aligned to potentially speed up crypto_xor() */ | ||||||
|  | -	u8 stream[CHACHA_BLOCK_SIZE] __aligned(sizeof(long)); | ||||||
|  | - | ||||||
|  | -	while (bytes >= CHACHA_BLOCK_SIZE) { | ||||||
|  | -		chacha_block(state, stream, nrounds); | ||||||
|  | -		crypto_xor_cpy(dst, src, stream, CHACHA_BLOCK_SIZE); | ||||||
|  | -		bytes -= CHACHA_BLOCK_SIZE; | ||||||
|  | -		dst += CHACHA_BLOCK_SIZE; | ||||||
|  | -		src += CHACHA_BLOCK_SIZE; | ||||||
|  | -	} | ||||||
|  | -	if (bytes) { | ||||||
|  | -		chacha_block(state, stream, nrounds); | ||||||
|  | -		crypto_xor_cpy(dst, src, stream, bytes); | ||||||
|  | -	} | ||||||
|  | -} | ||||||
|  | - | ||||||
|  |  static int chacha_stream_xor(struct skcipher_request *req, | ||||||
|  |  			     const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  |  { | ||||||
|  | @@ -48,8 +29,8 @@ static int chacha_stream_xor(struct skci | ||||||
|  |  		if (nbytes < walk.total) | ||||||
|  |  			nbytes = round_down(nbytes, CHACHA_BLOCK_SIZE); | ||||||
|  |   | ||||||
|  | -		chacha_docrypt(state, walk.dst.virt.addr, walk.src.virt.addr, | ||||||
|  | -			       nbytes, ctx->nrounds); | ||||||
|  | +		chacha_crypt_generic(state, walk.dst.virt.addr, | ||||||
|  | +				     walk.src.virt.addr, nbytes, ctx->nrounds); | ||||||
|  |  		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | @@ -58,41 +39,10 @@ static int chacha_stream_xor(struct skci | ||||||
|  |   | ||||||
|  |  void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  |  { | ||||||
|  | -	state[0]  = 0x61707865; /* "expa" */ | ||||||
|  | -	state[1]  = 0x3320646e; /* "nd 3" */ | ||||||
|  | -	state[2]  = 0x79622d32; /* "2-by" */ | ||||||
|  | -	state[3]  = 0x6b206574; /* "te k" */ | ||||||
|  | -	state[4]  = ctx->key[0]; | ||||||
|  | -	state[5]  = ctx->key[1]; | ||||||
|  | -	state[6]  = ctx->key[2]; | ||||||
|  | -	state[7]  = ctx->key[3]; | ||||||
|  | -	state[8]  = ctx->key[4]; | ||||||
|  | -	state[9]  = ctx->key[5]; | ||||||
|  | -	state[10] = ctx->key[6]; | ||||||
|  | -	state[11] = ctx->key[7]; | ||||||
|  | -	state[12] = get_unaligned_le32(iv +  0); | ||||||
|  | -	state[13] = get_unaligned_le32(iv +  4); | ||||||
|  | -	state[14] = get_unaligned_le32(iv +  8); | ||||||
|  | -	state[15] = get_unaligned_le32(iv + 12); | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  |  } | ||||||
|  |  EXPORT_SYMBOL_GPL(crypto_chacha_init); | ||||||
|  |   | ||||||
|  | -static int chacha_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			 unsigned int keysize, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | -	int i; | ||||||
|  | - | ||||||
|  | -	if (keysize != CHACHA_KEY_SIZE) | ||||||
|  | -		return -EINVAL; | ||||||
|  | - | ||||||
|  | -	for (i = 0; i < ARRAY_SIZE(ctx->key); i++) | ||||||
|  | -		ctx->key[i] = get_unaligned_le32(key + i * sizeof(u32)); | ||||||
|  | - | ||||||
|  | -	ctx->nrounds = nrounds; | ||||||
|  | -	return 0; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  |  int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  |  			   unsigned int keysize) | ||||||
|  |  { | ||||||
|  | @@ -126,7 +76,7 @@ int crypto_xchacha_crypt(struct skcipher | ||||||
|  |   | ||||||
|  |  	/* Compute the subkey given the original key and first 128 nonce bits */ | ||||||
|  |  	crypto_chacha_init(state, ctx, req->iv); | ||||||
|  | -	hchacha_block(state, subctx.key, ctx->nrounds); | ||||||
|  | +	hchacha_block_generic(state, subctx.key, ctx->nrounds); | ||||||
|  |  	subctx.nrounds = ctx->nrounds; | ||||||
|  |   | ||||||
|  |  	/* Build the real IV */ | ||||||
|  | --- a/include/crypto/chacha.h | ||||||
|  | +++ b/include/crypto/chacha.h | ||||||
|  | @@ -15,9 +15,8 @@ | ||||||
|  |  #ifndef _CRYPTO_CHACHA_H | ||||||
|  |  #define _CRYPTO_CHACHA_H | ||||||
|  |   | ||||||
|  | -#include <crypto/skcipher.h> | ||||||
|  | +#include <asm/unaligned.h> | ||||||
|  |  #include <linux/types.h> | ||||||
|  | -#include <linux/crypto.h> | ||||||
|  |   | ||||||
|  |  /* 32-bit stream position, then 96-bit nonce (RFC7539 convention) */ | ||||||
|  |  #define CHACHA_IV_SIZE		16 | ||||||
|  | @@ -29,26 +28,70 @@ | ||||||
|  |  /* 192-bit nonce, then 64-bit stream position */ | ||||||
|  |  #define XCHACHA_IV_SIZE		32 | ||||||
|  |   | ||||||
|  | -struct chacha_ctx { | ||||||
|  | -	u32 key[8]; | ||||||
|  | -	int nrounds; | ||||||
|  | -}; | ||||||
|  | - | ||||||
|  | -void chacha_block(u32 *state, u8 *stream, int nrounds); | ||||||
|  | +void chacha_block_generic(u32 *state, u8 *stream, int nrounds); | ||||||
|  |  static inline void chacha20_block(u32 *state, u8 *stream) | ||||||
|  |  { | ||||||
|  | -	chacha_block(state, stream, 20); | ||||||
|  | +	chacha_block_generic(state, stream, 20); | ||||||
|  |  } | ||||||
|  | -void hchacha_block(const u32 *in, u32 *out, int nrounds); | ||||||
|  |   | ||||||
|  | -void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv); | ||||||
|  | +void hchacha_block_arch(const u32 *state, u32 *out, int nrounds); | ||||||
|  | +void hchacha_block_generic(const u32 *state, u32 *out, int nrounds); | ||||||
|  | + | ||||||
|  | +static inline void hchacha_block(const u32 *state, u32 *out, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA)) | ||||||
|  | +		hchacha_block_arch(state, out, nrounds); | ||||||
|  | +	else | ||||||
|  | +		hchacha_block_generic(state, out, nrounds); | ||||||
|  | +} | ||||||
|  |   | ||||||
|  | -int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize); | ||||||
|  | -int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize); | ||||||
|  | +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv); | ||||||
|  | +static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	state[0]  = 0x61707865; /* "expa" */ | ||||||
|  | +	state[1]  = 0x3320646e; /* "nd 3" */ | ||||||
|  | +	state[2]  = 0x79622d32; /* "2-by" */ | ||||||
|  | +	state[3]  = 0x6b206574; /* "te k" */ | ||||||
|  | +	state[4]  = key[0]; | ||||||
|  | +	state[5]  = key[1]; | ||||||
|  | +	state[6]  = key[2]; | ||||||
|  | +	state[7]  = key[3]; | ||||||
|  | +	state[8]  = key[4]; | ||||||
|  | +	state[9]  = key[5]; | ||||||
|  | +	state[10] = key[6]; | ||||||
|  | +	state[11] = key[7]; | ||||||
|  | +	state[12] = get_unaligned_le32(iv +  0); | ||||||
|  | +	state[13] = get_unaligned_le32(iv +  4); | ||||||
|  | +	state[14] = get_unaligned_le32(iv +  8); | ||||||
|  | +	state[15] = get_unaligned_le32(iv + 12); | ||||||
|  | +} | ||||||
|  |   | ||||||
|  | -int crypto_chacha_crypt(struct skcipher_request *req); | ||||||
|  | -int crypto_xchacha_crypt(struct skcipher_request *req); | ||||||
|  | +static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA)) | ||||||
|  | +		chacha_init_arch(state, key, iv); | ||||||
|  | +	else | ||||||
|  | +		chacha_init_generic(state, key, iv); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +		       unsigned int bytes, int nrounds); | ||||||
|  | +void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +			  unsigned int bytes, int nrounds); | ||||||
|  | + | ||||||
|  | +static inline void chacha_crypt(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +				unsigned int bytes, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA)) | ||||||
|  | +		chacha_crypt_arch(state, dst, src, bytes, nrounds); | ||||||
|  | +	else | ||||||
|  | +		chacha_crypt_generic(state, dst, src, bytes, nrounds); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline void chacha20_crypt(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +				  unsigned int bytes) | ||||||
|  | +{ | ||||||
|  | +	chacha_crypt(state, dst, src, bytes, 20); | ||||||
|  | +} | ||||||
|  |   | ||||||
|  |  #endif /* _CRYPTO_CHACHA_H */ | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/include/crypto/internal/chacha.h | ||||||
|  | @@ -0,0 +1,53 @@ | ||||||
|  | +/* SPDX-License-Identifier: GPL-2.0 */ | ||||||
|  | + | ||||||
|  | +#ifndef _CRYPTO_INTERNAL_CHACHA_H | ||||||
|  | +#define _CRYPTO_INTERNAL_CHACHA_H | ||||||
|  | + | ||||||
|  | +#include <crypto/chacha.h> | ||||||
|  | +#include <crypto/internal/skcipher.h> | ||||||
|  | +#include <linux/crypto.h> | ||||||
|  | + | ||||||
|  | +struct chacha_ctx { | ||||||
|  | +	u32 key[8]; | ||||||
|  | +	int nrounds; | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv); | ||||||
|  | + | ||||||
|  | +static inline int chacha_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +				unsigned int keysize, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | +	int i; | ||||||
|  | + | ||||||
|  | +	if (keysize != CHACHA_KEY_SIZE) | ||||||
|  | +		return -EINVAL; | ||||||
|  | + | ||||||
|  | +	for (i = 0; i < ARRAY_SIZE(ctx->key); i++) | ||||||
|  | +		ctx->key[i] = get_unaligned_le32(key + i * sizeof(u32)); | ||||||
|  | + | ||||||
|  | +	ctx->nrounds = nrounds; | ||||||
|  | +	return 0; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline int chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +				  unsigned int keysize) | ||||||
|  | +{ | ||||||
|  | +	return chacha_setkey(tfm, key, keysize, 20); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int inline chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +				  unsigned int keysize) | ||||||
|  | +{ | ||||||
|  | +	return chacha_setkey(tfm, key, keysize, 12); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +			   unsigned int keysize); | ||||||
|  | +int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +			   unsigned int keysize); | ||||||
|  | + | ||||||
|  | +int crypto_chacha_crypt(struct skcipher_request *req); | ||||||
|  | +int crypto_xchacha_crypt(struct skcipher_request *req); | ||||||
|  | + | ||||||
|  | +#endif /* _CRYPTO_CHACHA_H */ | ||||||
|  | --- a/lib/Makefile | ||||||
|  | +++ b/lib/Makefile | ||||||
|  | @@ -26,8 +26,7 @@ endif | ||||||
|  |   | ||||||
|  |  lib-y := ctype.o string.o vsprintf.o cmdline.o \ | ||||||
|  |  	 rbtree.o radix-tree.o timerqueue.o xarray.o \ | ||||||
|  | -	 idr.o extable.o \ | ||||||
|  | -	 sha1.o chacha.o irq_regs.o argv_split.o \ | ||||||
|  | +	 idr.o extable.o sha1.o irq_regs.o argv_split.o \ | ||||||
|  |  	 flex_proportions.o ratelimit.o show_mem.o \ | ||||||
|  |  	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \ | ||||||
|  |  	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ | ||||||
|  | --- a/lib/crypto/Kconfig | ||||||
|  | +++ b/lib/crypto/Kconfig | ||||||
|  | @@ -8,6 +8,32 @@ config CRYPTO_LIB_AES | ||||||
|  |  config CRYPTO_LIB_ARC4 | ||||||
|  |  	tristate | ||||||
|  |   | ||||||
|  | +config CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  | +	tristate | ||||||
|  | +	help | ||||||
|  | +	  Declares whether the architecture provides an arch-specific | ||||||
|  | +	  accelerated implementation of the ChaCha library interface, | ||||||
|  | +	  either builtin or as a module. | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  | +	tristate | ||||||
|  | +	select CRYPTO_ALGAPI | ||||||
|  | +	help | ||||||
|  | +	  This symbol can be depended upon by arch implementations of the | ||||||
|  | +	  ChaCha library interface that require the generic code as a | ||||||
|  | +	  fallback, e.g., for SIMD implementations. If no arch specific | ||||||
|  | +	  implementation is enabled, this implementation serves the users | ||||||
|  | +	  of CRYPTO_LIB_CHACHA. | ||||||
|  | + | ||||||
|  | +config CRYPTO_LIB_CHACHA | ||||||
|  | +	tristate "ChaCha library interface" | ||||||
|  | +	depends on CRYPTO_ARCH_HAVE_LIB_CHACHA || !CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  | +	select CRYPTO_LIB_CHACHA_GENERIC if CRYPTO_ARCH_HAVE_LIB_CHACHA=n | ||||||
|  | +	help | ||||||
|  | +	  Enable the ChaCha library interface. This interface may be fulfilled | ||||||
|  | +	  by either the generic implementation or an arch-specific one, if one | ||||||
|  | +	  is available and enabled. | ||||||
|  | + | ||||||
|  |  config CRYPTO_LIB_DES | ||||||
|  |  	tristate | ||||||
|  |   | ||||||
|  | --- a/lib/crypto/Makefile | ||||||
|  | +++ b/lib/crypto/Makefile | ||||||
|  | @@ -1,5 +1,9 @@ | ||||||
|  |  # SPDX-License-Identifier: GPL-2.0 | ||||||
|  |   | ||||||
|  | +# chacha is used by the /dev/random driver which is always builtin | ||||||
|  | +obj-y						+= chacha.o | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC)		+= libchacha.o | ||||||
|  | + | ||||||
|  |  obj-$(CONFIG_CRYPTO_LIB_AES)			+= libaes.o | ||||||
|  |  libaes-y					:= aes.o | ||||||
|  |   | ||||||
|  | --- a/lib/chacha.c | ||||||
|  | +++ /dev/null | ||||||
|  | @@ -1,113 +0,0 @@ | ||||||
|  | -// SPDX-License-Identifier: GPL-2.0-or-later | ||||||
|  | -/* | ||||||
|  | - * The "hash function" used as the core of the ChaCha stream cipher (RFC7539) | ||||||
|  | - * | ||||||
|  | - * Copyright (C) 2015 Martin Willi | ||||||
|  | - */ | ||||||
|  | - | ||||||
|  | -#include <linux/kernel.h> | ||||||
|  | -#include <linux/export.h> | ||||||
|  | -#include <linux/bitops.h> | ||||||
|  | -#include <linux/cryptohash.h> | ||||||
|  | -#include <asm/unaligned.h> | ||||||
|  | -#include <crypto/chacha.h> | ||||||
|  | - | ||||||
|  | -static void chacha_permute(u32 *x, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	int i; | ||||||
|  | - | ||||||
|  | -	/* whitelist the allowed round counts */ | ||||||
|  | -	WARN_ON_ONCE(nrounds != 20 && nrounds != 12); | ||||||
|  | - | ||||||
|  | -	for (i = 0; i < nrounds; i += 2) { | ||||||
|  | -		x[0]  += x[4];    x[12] = rol32(x[12] ^ x[0],  16); | ||||||
|  | -		x[1]  += x[5];    x[13] = rol32(x[13] ^ x[1],  16); | ||||||
|  | -		x[2]  += x[6];    x[14] = rol32(x[14] ^ x[2],  16); | ||||||
|  | -		x[3]  += x[7];    x[15] = rol32(x[15] ^ x[3],  16); | ||||||
|  | - | ||||||
|  | -		x[8]  += x[12];   x[4]  = rol32(x[4]  ^ x[8],  12); | ||||||
|  | -		x[9]  += x[13];   x[5]  = rol32(x[5]  ^ x[9],  12); | ||||||
|  | -		x[10] += x[14];   x[6]  = rol32(x[6]  ^ x[10], 12); | ||||||
|  | -		x[11] += x[15];   x[7]  = rol32(x[7]  ^ x[11], 12); | ||||||
|  | - | ||||||
|  | -		x[0]  += x[4];    x[12] = rol32(x[12] ^ x[0],   8); | ||||||
|  | -		x[1]  += x[5];    x[13] = rol32(x[13] ^ x[1],   8); | ||||||
|  | -		x[2]  += x[6];    x[14] = rol32(x[14] ^ x[2],   8); | ||||||
|  | -		x[3]  += x[7];    x[15] = rol32(x[15] ^ x[3],   8); | ||||||
|  | - | ||||||
|  | -		x[8]  += x[12];   x[4]  = rol32(x[4]  ^ x[8],   7); | ||||||
|  | -		x[9]  += x[13];   x[5]  = rol32(x[5]  ^ x[9],   7); | ||||||
|  | -		x[10] += x[14];   x[6]  = rol32(x[6]  ^ x[10],  7); | ||||||
|  | -		x[11] += x[15];   x[7]  = rol32(x[7]  ^ x[11],  7); | ||||||
|  | - | ||||||
|  | -		x[0]  += x[5];    x[15] = rol32(x[15] ^ x[0],  16); | ||||||
|  | -		x[1]  += x[6];    x[12] = rol32(x[12] ^ x[1],  16); | ||||||
|  | -		x[2]  += x[7];    x[13] = rol32(x[13] ^ x[2],  16); | ||||||
|  | -		x[3]  += x[4];    x[14] = rol32(x[14] ^ x[3],  16); | ||||||
|  | - | ||||||
|  | -		x[10] += x[15];   x[5]  = rol32(x[5]  ^ x[10], 12); | ||||||
|  | -		x[11] += x[12];   x[6]  = rol32(x[6]  ^ x[11], 12); | ||||||
|  | -		x[8]  += x[13];   x[7]  = rol32(x[7]  ^ x[8],  12); | ||||||
|  | -		x[9]  += x[14];   x[4]  = rol32(x[4]  ^ x[9],  12); | ||||||
|  | - | ||||||
|  | -		x[0]  += x[5];    x[15] = rol32(x[15] ^ x[0],   8); | ||||||
|  | -		x[1]  += x[6];    x[12] = rol32(x[12] ^ x[1],   8); | ||||||
|  | -		x[2]  += x[7];    x[13] = rol32(x[13] ^ x[2],   8); | ||||||
|  | -		x[3]  += x[4];    x[14] = rol32(x[14] ^ x[3],   8); | ||||||
|  | - | ||||||
|  | -		x[10] += x[15];   x[5]  = rol32(x[5]  ^ x[10],  7); | ||||||
|  | -		x[11] += x[12];   x[6]  = rol32(x[6]  ^ x[11],  7); | ||||||
|  | -		x[8]  += x[13];   x[7]  = rol32(x[7]  ^ x[8],   7); | ||||||
|  | -		x[9]  += x[14];   x[4]  = rol32(x[4]  ^ x[9],   7); | ||||||
|  | -	} | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -/** | ||||||
|  | - * chacha_block - generate one keystream block and increment block counter | ||||||
|  | - * @state: input state matrix (16 32-bit words) | ||||||
|  | - * @stream: output keystream block (64 bytes) | ||||||
|  | - * @nrounds: number of rounds (20 or 12; 20 is recommended) | ||||||
|  | - * | ||||||
|  | - * This is the ChaCha core, a function from 64-byte strings to 64-byte strings. | ||||||
|  | - * The caller has already converted the endianness of the input.  This function | ||||||
|  | - * also handles incrementing the block counter in the input matrix. | ||||||
|  | - */ | ||||||
|  | -void chacha_block(u32 *state, u8 *stream, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	u32 x[16]; | ||||||
|  | -	int i; | ||||||
|  | - | ||||||
|  | -	memcpy(x, state, 64); | ||||||
|  | - | ||||||
|  | -	chacha_permute(x, nrounds); | ||||||
|  | - | ||||||
|  | -	for (i = 0; i < ARRAY_SIZE(x); i++) | ||||||
|  | -		put_unaligned_le32(x[i] + state[i], &stream[i * sizeof(u32)]); | ||||||
|  | - | ||||||
|  | -	state[12]++; | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL(chacha_block); | ||||||
|  | - | ||||||
|  | -/** | ||||||
|  | - * hchacha_block - abbreviated ChaCha core, for XChaCha | ||||||
|  | - * @in: input state matrix (16 32-bit words) | ||||||
|  | - * @out: output (8 32-bit words) | ||||||
|  | - * @nrounds: number of rounds (20 or 12; 20 is recommended) | ||||||
|  | - * | ||||||
|  | - * HChaCha is the ChaCha equivalent of HSalsa and is an intermediate step | ||||||
|  | - * towards XChaCha (see https://cr.yp.to/snuffle/xsalsa-20081128.pdf).  HChaCha | ||||||
|  | - * skips the final addition of the initial state, and outputs only certain words | ||||||
|  | - * of the state.  It should not be used for streaming directly. | ||||||
|  | - */ | ||||||
|  | -void hchacha_block(const u32 *in, u32 *out, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	u32 x[16]; | ||||||
|  | - | ||||||
|  | -	memcpy(x, in, 64); | ||||||
|  | - | ||||||
|  | -	chacha_permute(x, nrounds); | ||||||
|  | - | ||||||
|  | -	memcpy(&out[0], &x[0], 16); | ||||||
|  | -	memcpy(&out[4], &x[12], 16); | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL(hchacha_block); | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/lib/crypto/chacha.c | ||||||
|  | @@ -0,0 +1,115 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0-or-later | ||||||
|  | +/* | ||||||
|  | + * The "hash function" used as the core of the ChaCha stream cipher (RFC7539) | ||||||
|  | + * | ||||||
|  | + * Copyright (C) 2015 Martin Willi | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <linux/bug.h> | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | +#include <linux/export.h> | ||||||
|  | +#include <linux/bitops.h> | ||||||
|  | +#include <linux/string.h> | ||||||
|  | +#include <linux/cryptohash.h> | ||||||
|  | +#include <asm/unaligned.h> | ||||||
|  | +#include <crypto/chacha.h> | ||||||
|  | + | ||||||
|  | +static void chacha_permute(u32 *x, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	int i; | ||||||
|  | + | ||||||
|  | +	/* whitelist the allowed round counts */ | ||||||
|  | +	WARN_ON_ONCE(nrounds != 20 && nrounds != 12); | ||||||
|  | + | ||||||
|  | +	for (i = 0; i < nrounds; i += 2) { | ||||||
|  | +		x[0]  += x[4];    x[12] = rol32(x[12] ^ x[0],  16); | ||||||
|  | +		x[1]  += x[5];    x[13] = rol32(x[13] ^ x[1],  16); | ||||||
|  | +		x[2]  += x[6];    x[14] = rol32(x[14] ^ x[2],  16); | ||||||
|  | +		x[3]  += x[7];    x[15] = rol32(x[15] ^ x[3],  16); | ||||||
|  | + | ||||||
|  | +		x[8]  += x[12];   x[4]  = rol32(x[4]  ^ x[8],  12); | ||||||
|  | +		x[9]  += x[13];   x[5]  = rol32(x[5]  ^ x[9],  12); | ||||||
|  | +		x[10] += x[14];   x[6]  = rol32(x[6]  ^ x[10], 12); | ||||||
|  | +		x[11] += x[15];   x[7]  = rol32(x[7]  ^ x[11], 12); | ||||||
|  | + | ||||||
|  | +		x[0]  += x[4];    x[12] = rol32(x[12] ^ x[0],   8); | ||||||
|  | +		x[1]  += x[5];    x[13] = rol32(x[13] ^ x[1],   8); | ||||||
|  | +		x[2]  += x[6];    x[14] = rol32(x[14] ^ x[2],   8); | ||||||
|  | +		x[3]  += x[7];    x[15] = rol32(x[15] ^ x[3],   8); | ||||||
|  | + | ||||||
|  | +		x[8]  += x[12];   x[4]  = rol32(x[4]  ^ x[8],   7); | ||||||
|  | +		x[9]  += x[13];   x[5]  = rol32(x[5]  ^ x[9],   7); | ||||||
|  | +		x[10] += x[14];   x[6]  = rol32(x[6]  ^ x[10],  7); | ||||||
|  | +		x[11] += x[15];   x[7]  = rol32(x[7]  ^ x[11],  7); | ||||||
|  | + | ||||||
|  | +		x[0]  += x[5];    x[15] = rol32(x[15] ^ x[0],  16); | ||||||
|  | +		x[1]  += x[6];    x[12] = rol32(x[12] ^ x[1],  16); | ||||||
|  | +		x[2]  += x[7];    x[13] = rol32(x[13] ^ x[2],  16); | ||||||
|  | +		x[3]  += x[4];    x[14] = rol32(x[14] ^ x[3],  16); | ||||||
|  | + | ||||||
|  | +		x[10] += x[15];   x[5]  = rol32(x[5]  ^ x[10], 12); | ||||||
|  | +		x[11] += x[12];   x[6]  = rol32(x[6]  ^ x[11], 12); | ||||||
|  | +		x[8]  += x[13];   x[7]  = rol32(x[7]  ^ x[8],  12); | ||||||
|  | +		x[9]  += x[14];   x[4]  = rol32(x[4]  ^ x[9],  12); | ||||||
|  | + | ||||||
|  | +		x[0]  += x[5];    x[15] = rol32(x[15] ^ x[0],   8); | ||||||
|  | +		x[1]  += x[6];    x[12] = rol32(x[12] ^ x[1],   8); | ||||||
|  | +		x[2]  += x[7];    x[13] = rol32(x[13] ^ x[2],   8); | ||||||
|  | +		x[3]  += x[4];    x[14] = rol32(x[14] ^ x[3],   8); | ||||||
|  | + | ||||||
|  | +		x[10] += x[15];   x[5]  = rol32(x[5]  ^ x[10],  7); | ||||||
|  | +		x[11] += x[12];   x[6]  = rol32(x[6]  ^ x[11],  7); | ||||||
|  | +		x[8]  += x[13];   x[7]  = rol32(x[7]  ^ x[8],   7); | ||||||
|  | +		x[9]  += x[14];   x[4]  = rol32(x[4]  ^ x[9],   7); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +/** | ||||||
|  | + * chacha_block - generate one keystream block and increment block counter | ||||||
|  | + * @state: input state matrix (16 32-bit words) | ||||||
|  | + * @stream: output keystream block (64 bytes) | ||||||
|  | + * @nrounds: number of rounds (20 or 12; 20 is recommended) | ||||||
|  | + * | ||||||
|  | + * This is the ChaCha core, a function from 64-byte strings to 64-byte strings. | ||||||
|  | + * The caller has already converted the endianness of the input.  This function | ||||||
|  | + * also handles incrementing the block counter in the input matrix. | ||||||
|  | + */ | ||||||
|  | +void chacha_block_generic(u32 *state, u8 *stream, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	u32 x[16]; | ||||||
|  | +	int i; | ||||||
|  | + | ||||||
|  | +	memcpy(x, state, 64); | ||||||
|  | + | ||||||
|  | +	chacha_permute(x, nrounds); | ||||||
|  | + | ||||||
|  | +	for (i = 0; i < ARRAY_SIZE(x); i++) | ||||||
|  | +		put_unaligned_le32(x[i] + state[i], &stream[i * sizeof(u32)]); | ||||||
|  | + | ||||||
|  | +	state[12]++; | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_block_generic); | ||||||
|  | + | ||||||
|  | +/** | ||||||
|  | + * hchacha_block_generic - abbreviated ChaCha core, for XChaCha | ||||||
|  | + * @state: input state matrix (16 32-bit words) | ||||||
|  | + * @out: output (8 32-bit words) | ||||||
|  | + * @nrounds: number of rounds (20 or 12; 20 is recommended) | ||||||
|  | + * | ||||||
|  | + * HChaCha is the ChaCha equivalent of HSalsa and is an intermediate step | ||||||
|  | + * towards XChaCha (see https://cr.yp.to/snuffle/xsalsa-20081128.pdf).  HChaCha | ||||||
|  | + * skips the final addition of the initial state, and outputs only certain words | ||||||
|  | + * of the state.  It should not be used for streaming directly. | ||||||
|  | + */ | ||||||
|  | +void hchacha_block_generic(const u32 *state, u32 *stream, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	u32 x[16]; | ||||||
|  | + | ||||||
|  | +	memcpy(x, state, 64); | ||||||
|  | + | ||||||
|  | +	chacha_permute(x, nrounds); | ||||||
|  | + | ||||||
|  | +	memcpy(&stream[0], &x[0], 16); | ||||||
|  | +	memcpy(&stream[4], &x[12], 16); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(hchacha_block_generic); | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/lib/crypto/libchacha.c | ||||||
|  | @@ -0,0 +1,35 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0-or-later | ||||||
|  | +/* | ||||||
|  | + * The ChaCha stream cipher (RFC7539) | ||||||
|  | + * | ||||||
|  | + * Copyright (C) 2015 Martin Willi | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | +#include <linux/export.h> | ||||||
|  | +#include <linux/module.h> | ||||||
|  | + | ||||||
|  | +#include <crypto/algapi.h> // for crypto_xor_cpy | ||||||
|  | +#include <crypto/chacha.h> | ||||||
|  | + | ||||||
|  | +void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +			  unsigned int bytes, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	/* aligned to potentially speed up crypto_xor() */ | ||||||
|  | +	u8 stream[CHACHA_BLOCK_SIZE] __aligned(sizeof(long)); | ||||||
|  | + | ||||||
|  | +	while (bytes >= CHACHA_BLOCK_SIZE) { | ||||||
|  | +		chacha_block_generic(state, stream, nrounds); | ||||||
|  | +		crypto_xor_cpy(dst, src, stream, CHACHA_BLOCK_SIZE); | ||||||
|  | +		bytes -= CHACHA_BLOCK_SIZE; | ||||||
|  | +		dst += CHACHA_BLOCK_SIZE; | ||||||
|  | +		src += CHACHA_BLOCK_SIZE; | ||||||
|  | +	} | ||||||
|  | +	if (bytes) { | ||||||
|  | +		chacha_block_generic(state, stream, nrounds); | ||||||
|  | +		crypto_xor_cpy(dst, src, stream, bytes); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_crypt_generic); | ||||||
|  | + | ||||||
|  | +MODULE_LICENSE("GPL"); | ||||||
| @@ -0,0 +1,192 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:09 +0100 | ||||||
|  | Subject: [PATCH] crypto: x86/chacha - depend on generic chacha library instead | ||||||
|  |  of crypto driver | ||||||
|  |  | ||||||
|  | commit 28e8d89b1ce8d2e7badfb5f69971dd635acb8863 upstream. | ||||||
|  |  | ||||||
|  | In preparation of extending the x86 ChaCha driver to also expose the ChaCha | ||||||
|  | library interface, drop the dependency on the chacha_generic crypto driver | ||||||
|  | as a non-SIMD fallback, and depend on the generic ChaCha library directly. | ||||||
|  | This way, we only pull in the code we actually need, without registering | ||||||
|  | a set of ChaCha skciphers that we will never use. | ||||||
|  |  | ||||||
|  | Since turning the FPU on and off is cheap these days, simplify the SIMD | ||||||
|  | routine by dropping the per-page yield, which makes for a cleaner switch | ||||||
|  | to the library API as well. This also allows use to invoke the skcipher | ||||||
|  | walk routines in non-atomic mode. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/x86/crypto/chacha_glue.c | 90 ++++++++++++++--------------------- | ||||||
|  |  crypto/Kconfig                |  2 +- | ||||||
|  |  2 files changed, 36 insertions(+), 56 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/arch/x86/crypto/chacha_glue.c | ||||||
|  | +++ b/arch/x86/crypto/chacha_glue.c | ||||||
|  | @@ -123,37 +123,38 @@ static void chacha_dosimd(u32 *state, u8 | ||||||
|  |  	} | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | -static int chacha_simd_stream_xor(struct skcipher_walk *walk, | ||||||
|  | +static int chacha_simd_stream_xor(struct skcipher_request *req, | ||||||
|  |  				  const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  |  { | ||||||
|  |  	u32 *state, state_buf[16 + 2] __aligned(8); | ||||||
|  | -	int next_yield = 4096; /* bytes until next FPU yield */ | ||||||
|  | -	int err = 0; | ||||||
|  | +	struct skcipher_walk walk; | ||||||
|  | +	int err; | ||||||
|  | + | ||||||
|  | +	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  |   | ||||||
|  |  	BUILD_BUG_ON(CHACHA_STATE_ALIGN != 16); | ||||||
|  |  	state = PTR_ALIGN(state_buf + 0, CHACHA_STATE_ALIGN); | ||||||
|  |   | ||||||
|  | -	crypto_chacha_init(state, ctx, iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  |   | ||||||
|  | -	while (walk->nbytes > 0) { | ||||||
|  | -		unsigned int nbytes = walk->nbytes; | ||||||
|  | +	while (walk.nbytes > 0) { | ||||||
|  | +		unsigned int nbytes = walk.nbytes; | ||||||
|  |   | ||||||
|  | -		if (nbytes < walk->total) { | ||||||
|  | -			nbytes = round_down(nbytes, walk->stride); | ||||||
|  | -			next_yield -= nbytes; | ||||||
|  | -		} | ||||||
|  | - | ||||||
|  | -		chacha_dosimd(state, walk->dst.virt.addr, walk->src.virt.addr, | ||||||
|  | -			      nbytes, ctx->nrounds); | ||||||
|  | +		if (nbytes < walk.total) | ||||||
|  | +			nbytes = round_down(nbytes, walk.stride); | ||||||
|  |   | ||||||
|  | -		if (next_yield <= 0) { | ||||||
|  | -			/* temporarily allow preemption */ | ||||||
|  | -			kernel_fpu_end(); | ||||||
|  | +		if (!crypto_simd_usable()) { | ||||||
|  | +			chacha_crypt_generic(state, walk.dst.virt.addr, | ||||||
|  | +					     walk.src.virt.addr, nbytes, | ||||||
|  | +					     ctx->nrounds); | ||||||
|  | +		} else { | ||||||
|  |  			kernel_fpu_begin(); | ||||||
|  | -			next_yield = 4096; | ||||||
|  | +			chacha_dosimd(state, walk.dst.virt.addr, | ||||||
|  | +				      walk.src.virt.addr, nbytes, | ||||||
|  | +				      ctx->nrounds); | ||||||
|  | +			kernel_fpu_end(); | ||||||
|  |  		} | ||||||
|  | - | ||||||
|  | -		err = skcipher_walk_done(walk, walk->nbytes - nbytes); | ||||||
|  | +		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  |  	return err; | ||||||
|  | @@ -163,55 +164,34 @@ static int chacha_simd(struct skcipher_r | ||||||
|  |  { | ||||||
|  |  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  |  	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | -	struct skcipher_walk walk; | ||||||
|  | -	int err; | ||||||
|  | - | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_chacha_crypt(req); | ||||||
|  |   | ||||||
|  | -	err = skcipher_walk_virt(&walk, req, true); | ||||||
|  | -	if (err) | ||||||
|  | -		return err; | ||||||
|  | - | ||||||
|  | -	kernel_fpu_begin(); | ||||||
|  | -	err = chacha_simd_stream_xor(&walk, ctx, req->iv); | ||||||
|  | -	kernel_fpu_end(); | ||||||
|  | -	return err; | ||||||
|  | +	return chacha_simd_stream_xor(req, ctx, req->iv); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  static int xchacha_simd(struct skcipher_request *req) | ||||||
|  |  { | ||||||
|  |  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  |  	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | -	struct skcipher_walk walk; | ||||||
|  | -	struct chacha_ctx subctx; | ||||||
|  |  	u32 *state, state_buf[16 + 2] __aligned(8); | ||||||
|  | +	struct chacha_ctx subctx; | ||||||
|  |  	u8 real_iv[16]; | ||||||
|  | -	int err; | ||||||
|  | - | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_xchacha_crypt(req); | ||||||
|  | - | ||||||
|  | -	err = skcipher_walk_virt(&walk, req, true); | ||||||
|  | -	if (err) | ||||||
|  | -		return err; | ||||||
|  |   | ||||||
|  |  	BUILD_BUG_ON(CHACHA_STATE_ALIGN != 16); | ||||||
|  |  	state = PTR_ALIGN(state_buf + 0, CHACHA_STATE_ALIGN); | ||||||
|  | -	crypto_chacha_init(state, ctx, req->iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  |   | ||||||
|  | -	kernel_fpu_begin(); | ||||||
|  | - | ||||||
|  | -	hchacha_block_ssse3(state, subctx.key, ctx->nrounds); | ||||||
|  | +	if (req->cryptlen > CHACHA_BLOCK_SIZE && crypto_simd_usable()) { | ||||||
|  | +		kernel_fpu_begin(); | ||||||
|  | +		hchacha_block_ssse3(state, subctx.key, ctx->nrounds); | ||||||
|  | +		kernel_fpu_end(); | ||||||
|  | +	} else { | ||||||
|  | +		hchacha_block_generic(state, subctx.key, ctx->nrounds); | ||||||
|  | +	} | ||||||
|  |  	subctx.nrounds = ctx->nrounds; | ||||||
|  |   | ||||||
|  |  	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  |  	memcpy(&real_iv[8], req->iv + 16, 8); | ||||||
|  | -	err = chacha_simd_stream_xor(&walk, &subctx, real_iv); | ||||||
|  | - | ||||||
|  | -	kernel_fpu_end(); | ||||||
|  | - | ||||||
|  | -	return err; | ||||||
|  | +	return chacha_simd_stream_xor(req, &subctx, real_iv); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  static struct skcipher_alg algs[] = { | ||||||
|  | @@ -227,7 +207,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  |  		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  |  		.encrypt		= chacha_simd, | ||||||
|  |  		.decrypt		= chacha_simd, | ||||||
|  |  	}, { | ||||||
|  | @@ -242,7 +222,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  |  		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  |  		.encrypt		= xchacha_simd, | ||||||
|  |  		.decrypt		= xchacha_simd, | ||||||
|  |  	}, { | ||||||
|  | @@ -257,7 +237,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  |  		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha12_setkey, | ||||||
|  | +		.setkey			= chacha12_setkey, | ||||||
|  |  		.encrypt		= xchacha_simd, | ||||||
|  |  		.decrypt		= xchacha_simd, | ||||||
|  |  	}, | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -1417,7 +1417,7 @@ config CRYPTO_CHACHA20_X86_64 | ||||||
|  |  	tristate "ChaCha stream cipher algorithms (x86_64/SSSE3/AVX2/AVX-512VL)" | ||||||
|  |  	depends on X86 && 64BIT | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  | -	select CRYPTO_CHACHA20 | ||||||
|  | +	select CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  |  	help | ||||||
|  |  	  SSSE3, AVX2, and AVX-512VL optimized implementations of the ChaCha20, | ||||||
|  |  	  XChaCha20, and XChaCha12 stream ciphers. | ||||||
| @@ -0,0 +1,205 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:10 +0100 | ||||||
|  | Subject: [PATCH] crypto: x86/chacha - expose SIMD ChaCha routine as library | ||||||
|  |  function | ||||||
|  |  | ||||||
|  | commit 84e03fa39fbe95a5567d43bff458c6d3b3a23ad1 upstream. | ||||||
|  |  | ||||||
|  | Wire the existing x86 SIMD ChaCha code into the new ChaCha library | ||||||
|  | interface, so that users of the library interface will get the | ||||||
|  | accelerated version when available. | ||||||
|  |  | ||||||
|  | Given that calls into the library API will always go through the | ||||||
|  | routines in this module if it is enabled, switch to static keys | ||||||
|  | to select the optimal implementation available (which may be none | ||||||
|  | at all, in which case we defer to the generic implementation for | ||||||
|  | all invocations). | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/x86/crypto/chacha_glue.c | 91 +++++++++++++++++++++++++---------- | ||||||
|  |  crypto/Kconfig                |  1 + | ||||||
|  |  include/crypto/chacha.h       |  6 +++ | ||||||
|  |  3 files changed, 73 insertions(+), 25 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/arch/x86/crypto/chacha_glue.c | ||||||
|  | +++ b/arch/x86/crypto/chacha_glue.c | ||||||
|  | @@ -21,24 +21,24 @@ asmlinkage void chacha_block_xor_ssse3(u | ||||||
|  |  asmlinkage void chacha_4block_xor_ssse3(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  					unsigned int len, int nrounds); | ||||||
|  |  asmlinkage void hchacha_block_ssse3(const u32 *state, u32 *out, int nrounds); | ||||||
|  | -#ifdef CONFIG_AS_AVX2 | ||||||
|  | + | ||||||
|  |  asmlinkage void chacha_2block_xor_avx2(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  				       unsigned int len, int nrounds); | ||||||
|  |  asmlinkage void chacha_4block_xor_avx2(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  				       unsigned int len, int nrounds); | ||||||
|  |  asmlinkage void chacha_8block_xor_avx2(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  				       unsigned int len, int nrounds); | ||||||
|  | -static bool chacha_use_avx2; | ||||||
|  | -#ifdef CONFIG_AS_AVX512 | ||||||
|  | + | ||||||
|  |  asmlinkage void chacha_2block_xor_avx512vl(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  					   unsigned int len, int nrounds); | ||||||
|  |  asmlinkage void chacha_4block_xor_avx512vl(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  					   unsigned int len, int nrounds); | ||||||
|  |  asmlinkage void chacha_8block_xor_avx512vl(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  					   unsigned int len, int nrounds); | ||||||
|  | -static bool chacha_use_avx512vl; | ||||||
|  | -#endif | ||||||
|  | -#endif | ||||||
|  | + | ||||||
|  | +static __ro_after_init DEFINE_STATIC_KEY_FALSE(chacha_use_simd); | ||||||
|  | +static __ro_after_init DEFINE_STATIC_KEY_FALSE(chacha_use_avx2); | ||||||
|  | +static __ro_after_init DEFINE_STATIC_KEY_FALSE(chacha_use_avx512vl); | ||||||
|  |   | ||||||
|  |  static unsigned int chacha_advance(unsigned int len, unsigned int maxblocks) | ||||||
|  |  { | ||||||
|  | @@ -49,9 +49,8 @@ static unsigned int chacha_advance(unsig | ||||||
|  |  static void chacha_dosimd(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  			  unsigned int bytes, int nrounds) | ||||||
|  |  { | ||||||
|  | -#ifdef CONFIG_AS_AVX2 | ||||||
|  | -#ifdef CONFIG_AS_AVX512 | ||||||
|  | -	if (chacha_use_avx512vl) { | ||||||
|  | +	if (IS_ENABLED(CONFIG_AS_AVX512) && | ||||||
|  | +	    static_branch_likely(&chacha_use_avx512vl)) { | ||||||
|  |  		while (bytes >= CHACHA_BLOCK_SIZE * 8) { | ||||||
|  |  			chacha_8block_xor_avx512vl(state, dst, src, bytes, | ||||||
|  |  						   nrounds); | ||||||
|  | @@ -79,8 +78,9 @@ static void chacha_dosimd(u32 *state, u8 | ||||||
|  |  			return; | ||||||
|  |  		} | ||||||
|  |  	} | ||||||
|  | -#endif | ||||||
|  | -	if (chacha_use_avx2) { | ||||||
|  | + | ||||||
|  | +	if (IS_ENABLED(CONFIG_AS_AVX2) && | ||||||
|  | +	    static_branch_likely(&chacha_use_avx2)) { | ||||||
|  |  		while (bytes >= CHACHA_BLOCK_SIZE * 8) { | ||||||
|  |  			chacha_8block_xor_avx2(state, dst, src, bytes, nrounds); | ||||||
|  |  			bytes -= CHACHA_BLOCK_SIZE * 8; | ||||||
|  | @@ -104,7 +104,7 @@ static void chacha_dosimd(u32 *state, u8 | ||||||
|  |  			return; | ||||||
|  |  		} | ||||||
|  |  	} | ||||||
|  | -#endif | ||||||
|  | + | ||||||
|  |  	while (bytes >= CHACHA_BLOCK_SIZE * 4) { | ||||||
|  |  		chacha_4block_xor_ssse3(state, dst, src, bytes, nrounds); | ||||||
|  |  		bytes -= CHACHA_BLOCK_SIZE * 4; | ||||||
|  | @@ -123,6 +123,43 @@ static void chacha_dosimd(u32 *state, u8 | ||||||
|  |  	} | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	state = PTR_ALIGN(state, CHACHA_STATE_ALIGN); | ||||||
|  | + | ||||||
|  | +	if (!static_branch_likely(&chacha_use_simd) || !crypto_simd_usable()) { | ||||||
|  | +		hchacha_block_generic(state, stream, nrounds); | ||||||
|  | +	} else { | ||||||
|  | +		kernel_fpu_begin(); | ||||||
|  | +		hchacha_block_ssse3(state, stream, nrounds); | ||||||
|  | +		kernel_fpu_end(); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(hchacha_block_arch); | ||||||
|  | + | ||||||
|  | +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	state = PTR_ALIGN(state, CHACHA_STATE_ALIGN); | ||||||
|  | + | ||||||
|  | +	chacha_init_generic(state, key, iv); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_init_arch); | ||||||
|  | + | ||||||
|  | +void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  | +		       int nrounds) | ||||||
|  | +{ | ||||||
|  | +	state = PTR_ALIGN(state, CHACHA_STATE_ALIGN); | ||||||
|  | + | ||||||
|  | +	if (!static_branch_likely(&chacha_use_simd) || !crypto_simd_usable() || | ||||||
|  | +	    bytes <= CHACHA_BLOCK_SIZE) | ||||||
|  | +		return chacha_crypt_generic(state, dst, src, bytes, nrounds); | ||||||
|  | + | ||||||
|  | +	kernel_fpu_begin(); | ||||||
|  | +	chacha_dosimd(state, dst, src, bytes, nrounds); | ||||||
|  | +	kernel_fpu_end(); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_crypt_arch); | ||||||
|  | + | ||||||
|  |  static int chacha_simd_stream_xor(struct skcipher_request *req, | ||||||
|  |  				  const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  |  { | ||||||
|  | @@ -143,7 +180,8 @@ static int chacha_simd_stream_xor(struct | ||||||
|  |  		if (nbytes < walk.total) | ||||||
|  |  			nbytes = round_down(nbytes, walk.stride); | ||||||
|  |   | ||||||
|  | -		if (!crypto_simd_usable()) { | ||||||
|  | +		if (!static_branch_likely(&chacha_use_simd) || | ||||||
|  | +		    !crypto_simd_usable()) { | ||||||
|  |  			chacha_crypt_generic(state, walk.dst.virt.addr, | ||||||
|  |  					     walk.src.virt.addr, nbytes, | ||||||
|  |  					     ctx->nrounds); | ||||||
|  | @@ -246,18 +284,21 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  static int __init chacha_simd_mod_init(void) | ||||||
|  |  { | ||||||
|  |  	if (!boot_cpu_has(X86_FEATURE_SSSE3)) | ||||||
|  | -		return -ENODEV; | ||||||
|  | +		return 0; | ||||||
|  |   | ||||||
|  | -#ifdef CONFIG_AS_AVX2 | ||||||
|  | -	chacha_use_avx2 = boot_cpu_has(X86_FEATURE_AVX) && | ||||||
|  | -			  boot_cpu_has(X86_FEATURE_AVX2) && | ||||||
|  | -			  cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL); | ||||||
|  | -#ifdef CONFIG_AS_AVX512 | ||||||
|  | -	chacha_use_avx512vl = chacha_use_avx2 && | ||||||
|  | -			      boot_cpu_has(X86_FEATURE_AVX512VL) && | ||||||
|  | -			      boot_cpu_has(X86_FEATURE_AVX512BW); /* kmovq */ | ||||||
|  | -#endif | ||||||
|  | -#endif | ||||||
|  | +	static_branch_enable(&chacha_use_simd); | ||||||
|  | + | ||||||
|  | +	if (IS_ENABLED(CONFIG_AS_AVX2) && | ||||||
|  | +	    boot_cpu_has(X86_FEATURE_AVX) && | ||||||
|  | +	    boot_cpu_has(X86_FEATURE_AVX2) && | ||||||
|  | +	    cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL)) { | ||||||
|  | +		static_branch_enable(&chacha_use_avx2); | ||||||
|  | + | ||||||
|  | +		if (IS_ENABLED(CONFIG_AS_AVX512) && | ||||||
|  | +		    boot_cpu_has(X86_FEATURE_AVX512VL) && | ||||||
|  | +		    boot_cpu_has(X86_FEATURE_AVX512BW)) /* kmovq */ | ||||||
|  | +			static_branch_enable(&chacha_use_avx512vl); | ||||||
|  | +	} | ||||||
|  |  	return crypto_register_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -1418,6 +1418,7 @@ config CRYPTO_CHACHA20_X86_64 | ||||||
|  |  	depends on X86 && 64BIT | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  |  	select CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  | +	select CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  |  	help | ||||||
|  |  	  SSSE3, AVX2, and AVX-512VL optimized implementations of the ChaCha20, | ||||||
|  |  	  XChaCha20, and XChaCha12 stream ciphers. | ||||||
|  | --- a/include/crypto/chacha.h | ||||||
|  | +++ b/include/crypto/chacha.h | ||||||
|  | @@ -25,6 +25,12 @@ | ||||||
|  |  #define CHACHA_BLOCK_SIZE	64 | ||||||
|  |  #define CHACHAPOLY_IV_SIZE	12 | ||||||
|  |   | ||||||
|  | +#ifdef CONFIG_X86_64 | ||||||
|  | +#define CHACHA_STATE_WORDS	((CHACHA_BLOCK_SIZE + 12) / sizeof(u32)) | ||||||
|  | +#else | ||||||
|  | +#define CHACHA_STATE_WORDS	(CHACHA_BLOCK_SIZE / sizeof(u32)) | ||||||
|  | +#endif | ||||||
|  | + | ||||||
|  |  /* 192-bit nonce, then 64-bit stream position */ | ||||||
|  |  #define XCHACHA_IV_SIZE		32 | ||||||
|  |   | ||||||
| @@ -0,0 +1,129 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:11 +0100 | ||||||
|  | Subject: [PATCH] crypto: arm64/chacha - depend on generic chacha library | ||||||
|  |  instead of crypto driver | ||||||
|  |  | ||||||
|  | commit c77da4867cbb7841177275dbb250f5c09679fae4 upstream. | ||||||
|  |  | ||||||
|  | Depend on the generic ChaCha library routines instead of pulling in the | ||||||
|  | generic ChaCha skcipher driver, which is more than we need, and makes | ||||||
|  | managing the dependencies between the generic library, generic driver, | ||||||
|  | accelerated library and driver more complicated. | ||||||
|  |  | ||||||
|  | While at it, drop the logic to prefer the scalar code on short inputs. | ||||||
|  | Turning the NEON on and off is cheap these days, and one major use case | ||||||
|  | for ChaCha20 is ChaCha20-Poly1305, which is guaranteed to hit the scalar | ||||||
|  | path upon every invocation  (when doing the Poly1305 nonce generation) | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm64/crypto/Kconfig            |  2 +- | ||||||
|  |  arch/arm64/crypto/chacha-neon-glue.c | 40 +++++++++++++++------------- | ||||||
|  |  2 files changed, 23 insertions(+), 19 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/arch/arm64/crypto/Kconfig | ||||||
|  | +++ b/arch/arm64/crypto/Kconfig | ||||||
|  | @@ -103,7 +103,7 @@ config CRYPTO_CHACHA20_NEON | ||||||
|  |  	tristate "ChaCha20, XChaCha20, and XChaCha12 stream ciphers using NEON instructions" | ||||||
|  |  	depends on KERNEL_MODE_NEON | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  | -	select CRYPTO_CHACHA20 | ||||||
|  | +	select CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  |   | ||||||
|  |  config CRYPTO_NHPOLY1305_NEON | ||||||
|  |  	tristate "NHPoly1305 hash function using NEON instructions (for Adiantum)" | ||||||
|  | --- a/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | +++ b/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | @@ -68,7 +68,7 @@ static int chacha_neon_stream_xor(struct | ||||||
|  |   | ||||||
|  |  	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  |   | ||||||
|  | -	crypto_chacha_init(state, ctx, iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  |   | ||||||
|  |  	while (walk.nbytes > 0) { | ||||||
|  |  		unsigned int nbytes = walk.nbytes; | ||||||
|  | @@ -76,10 +76,16 @@ static int chacha_neon_stream_xor(struct | ||||||
|  |  		if (nbytes < walk.total) | ||||||
|  |  			nbytes = rounddown(nbytes, walk.stride); | ||||||
|  |   | ||||||
|  | -		kernel_neon_begin(); | ||||||
|  | -		chacha_doneon(state, walk.dst.virt.addr, walk.src.virt.addr, | ||||||
|  | -			      nbytes, ctx->nrounds); | ||||||
|  | -		kernel_neon_end(); | ||||||
|  | +		if (!crypto_simd_usable()) { | ||||||
|  | +			chacha_crypt_generic(state, walk.dst.virt.addr, | ||||||
|  | +					     walk.src.virt.addr, nbytes, | ||||||
|  | +					     ctx->nrounds); | ||||||
|  | +		} else { | ||||||
|  | +			kernel_neon_begin(); | ||||||
|  | +			chacha_doneon(state, walk.dst.virt.addr, | ||||||
|  | +				      walk.src.virt.addr, nbytes, ctx->nrounds); | ||||||
|  | +			kernel_neon_end(); | ||||||
|  | +		} | ||||||
|  |  		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | @@ -91,9 +97,6 @@ static int chacha_neon(struct skcipher_r | ||||||
|  |  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  |  	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  |   | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_chacha_crypt(req); | ||||||
|  | - | ||||||
|  |  	return chacha_neon_stream_xor(req, ctx, req->iv); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | @@ -105,14 +108,15 @@ static int xchacha_neon(struct skcipher_ | ||||||
|  |  	u32 state[16]; | ||||||
|  |  	u8 real_iv[16]; | ||||||
|  |   | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_xchacha_crypt(req); | ||||||
|  | - | ||||||
|  | -	crypto_chacha_init(state, ctx, req->iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  |   | ||||||
|  | -	kernel_neon_begin(); | ||||||
|  | -	hchacha_block_neon(state, subctx.key, ctx->nrounds); | ||||||
|  | -	kernel_neon_end(); | ||||||
|  | +	if (crypto_simd_usable()) { | ||||||
|  | +		kernel_neon_begin(); | ||||||
|  | +		hchacha_block_neon(state, subctx.key, ctx->nrounds); | ||||||
|  | +		kernel_neon_end(); | ||||||
|  | +	} else { | ||||||
|  | +		hchacha_block_generic(state, subctx.key, ctx->nrounds); | ||||||
|  | +	} | ||||||
|  |  	subctx.nrounds = ctx->nrounds; | ||||||
|  |   | ||||||
|  |  	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  | @@ -134,7 +138,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  |  		.walksize		= 5 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  |  		.encrypt		= chacha_neon, | ||||||
|  |  		.decrypt		= chacha_neon, | ||||||
|  |  	}, { | ||||||
|  | @@ -150,7 +154,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  |  		.walksize		= 5 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  |  		.encrypt		= xchacha_neon, | ||||||
|  |  		.decrypt		= xchacha_neon, | ||||||
|  |  	}, { | ||||||
|  | @@ -166,7 +170,7 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  |  		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  |  		.walksize		= 5 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha12_setkey, | ||||||
|  | +		.setkey			= chacha12_setkey, | ||||||
|  |  		.encrypt		= xchacha_neon, | ||||||
|  |  		.decrypt		= xchacha_neon, | ||||||
|  |  	} | ||||||
| @@ -0,0 +1,138 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:12 +0100 | ||||||
|  | Subject: [PATCH] crypto: arm64/chacha - expose arm64 ChaCha routine as library | ||||||
|  |  function | ||||||
|  |  | ||||||
|  | commit b3aad5bad26a01a4bd8c49a5c5f52aec665f3b7c upstream. | ||||||
|  |  | ||||||
|  | Expose the accelerated NEON ChaCha routine directly as a symbol | ||||||
|  | export so that users of the ChaCha library API can use it directly. | ||||||
|  |  | ||||||
|  | Given that calls into the library API will always go through the | ||||||
|  | routines in this module if it is enabled, switch to static keys | ||||||
|  | to select the optimal implementation available (which may be none | ||||||
|  | at all, in which case we defer to the generic implementation for | ||||||
|  | all invocations). | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm64/crypto/Kconfig            |  1 + | ||||||
|  |  arch/arm64/crypto/chacha-neon-glue.c | 53 ++++++++++++++++++++++------ | ||||||
|  |  2 files changed, 43 insertions(+), 11 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/arch/arm64/crypto/Kconfig | ||||||
|  | +++ b/arch/arm64/crypto/Kconfig | ||||||
|  | @@ -104,6 +104,7 @@ config CRYPTO_CHACHA20_NEON | ||||||
|  |  	depends on KERNEL_MODE_NEON | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  |  	select CRYPTO_LIB_CHACHA_GENERIC | ||||||
|  | +	select CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  |   | ||||||
|  |  config CRYPTO_NHPOLY1305_NEON | ||||||
|  |  	tristate "NHPoly1305 hash function using NEON instructions (for Adiantum)" | ||||||
|  | --- a/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | +++ b/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | @@ -23,6 +23,7 @@ | ||||||
|  |  #include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  | +#include <linux/jump_label.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  |  #include <linux/module.h> | ||||||
|  |   | ||||||
|  | @@ -36,6 +37,8 @@ asmlinkage void chacha_4block_xor_neon(u | ||||||
|  |  				       int nrounds, int bytes); | ||||||
|  |  asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds); | ||||||
|  |   | ||||||
|  | +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); | ||||||
|  | + | ||||||
|  |  static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, | ||||||
|  |  			  int bytes, int nrounds) | ||||||
|  |  { | ||||||
|  | @@ -59,6 +62,37 @@ static void chacha_doneon(u32 *state, u8 | ||||||
|  |  	} | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (!static_branch_likely(&have_neon) || !crypto_simd_usable()) { | ||||||
|  | +		hchacha_block_generic(state, stream, nrounds); | ||||||
|  | +	} else { | ||||||
|  | +		kernel_neon_begin(); | ||||||
|  | +		hchacha_block_neon(state, stream, nrounds); | ||||||
|  | +		kernel_neon_end(); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(hchacha_block_arch); | ||||||
|  | + | ||||||
|  | +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	chacha_init_generic(state, key, iv); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_init_arch); | ||||||
|  | + | ||||||
|  | +void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  | +		       int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (!static_branch_likely(&have_neon) || bytes <= CHACHA_BLOCK_SIZE || | ||||||
|  | +	    !crypto_simd_usable()) | ||||||
|  | +		return chacha_crypt_generic(state, dst, src, bytes, nrounds); | ||||||
|  | + | ||||||
|  | +	kernel_neon_begin(); | ||||||
|  | +	chacha_doneon(state, dst, src, bytes, nrounds); | ||||||
|  | +	kernel_neon_end(); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_crypt_arch); | ||||||
|  | + | ||||||
|  |  static int chacha_neon_stream_xor(struct skcipher_request *req, | ||||||
|  |  				  const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  |  { | ||||||
|  | @@ -76,7 +110,8 @@ static int chacha_neon_stream_xor(struct | ||||||
|  |  		if (nbytes < walk.total) | ||||||
|  |  			nbytes = rounddown(nbytes, walk.stride); | ||||||
|  |   | ||||||
|  | -		if (!crypto_simd_usable()) { | ||||||
|  | +		if (!static_branch_likely(&have_neon) || | ||||||
|  | +		    !crypto_simd_usable()) { | ||||||
|  |  			chacha_crypt_generic(state, walk.dst.virt.addr, | ||||||
|  |  					     walk.src.virt.addr, nbytes, | ||||||
|  |  					     ctx->nrounds); | ||||||
|  | @@ -109,14 +144,7 @@ static int xchacha_neon(struct skcipher_ | ||||||
|  |  	u8 real_iv[16]; | ||||||
|  |   | ||||||
|  |  	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  | - | ||||||
|  | -	if (crypto_simd_usable()) { | ||||||
|  | -		kernel_neon_begin(); | ||||||
|  | -		hchacha_block_neon(state, subctx.key, ctx->nrounds); | ||||||
|  | -		kernel_neon_end(); | ||||||
|  | -	} else { | ||||||
|  | -		hchacha_block_generic(state, subctx.key, ctx->nrounds); | ||||||
|  | -	} | ||||||
|  | +	hchacha_block_arch(state, subctx.key, ctx->nrounds); | ||||||
|  |  	subctx.nrounds = ctx->nrounds; | ||||||
|  |   | ||||||
|  |  	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  | @@ -179,14 +207,17 @@ static struct skcipher_alg algs[] = { | ||||||
|  |  static int __init chacha_simd_mod_init(void) | ||||||
|  |  { | ||||||
|  |  	if (!cpu_have_named_feature(ASIMD)) | ||||||
|  | -		return -ENODEV; | ||||||
|  | +		return 0; | ||||||
|  | + | ||||||
|  | +	static_branch_enable(&have_neon); | ||||||
|  |   | ||||||
|  |  	return crypto_register_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  static void __exit chacha_simd_mod_fini(void) | ||||||
|  |  { | ||||||
|  | -	crypto_unregister_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  | +	if (cpu_have_named_feature(ASIMD)) | ||||||
|  | +		crypto_unregister_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  module_init(chacha_simd_mod_init); | ||||||
| @@ -0,0 +1,480 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:13 +0100 | ||||||
|  | Subject: [PATCH] crypto: arm/chacha - import Eric Biggers's scalar accelerated | ||||||
|  |  ChaCha code | ||||||
|  |  | ||||||
|  | commit 29621d099f9c642b22a69dc8e7e20c108473a392 upstream. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm/crypto/chacha-scalar-core.S | 461 +++++++++++++++++++++++++++ | ||||||
|  |  1 file changed, 461 insertions(+) | ||||||
|  |  create mode 100644 arch/arm/crypto/chacha-scalar-core.S | ||||||
|  |  | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/arch/arm/crypto/chacha-scalar-core.S | ||||||
|  | @@ -0,0 +1,461 @@ | ||||||
|  | +/* SPDX-License-Identifier: GPL-2.0 */ | ||||||
|  | +/* | ||||||
|  | + * Copyright (C) 2018 Google, Inc. | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <linux/linkage.h> | ||||||
|  | +#include <asm/assembler.h> | ||||||
|  | + | ||||||
|  | +/* | ||||||
|  | + * Design notes: | ||||||
|  | + * | ||||||
|  | + * 16 registers would be needed to hold the state matrix, but only 14 are | ||||||
|  | + * available because 'sp' and 'pc' cannot be used.  So we spill the elements | ||||||
|  | + * (x8, x9) to the stack and swap them out with (x10, x11).  This adds one | ||||||
|  | + * 'ldrd' and one 'strd' instruction per round. | ||||||
|  | + * | ||||||
|  | + * All rotates are performed using the implicit rotate operand accepted by the | ||||||
|  | + * 'add' and 'eor' instructions.  This is faster than using explicit rotate | ||||||
|  | + * instructions.  To make this work, we allow the values in the second and last | ||||||
|  | + * rows of the ChaCha state matrix (rows 'b' and 'd') to temporarily have the | ||||||
|  | + * wrong rotation amount.  The rotation amount is then fixed up just in time | ||||||
|  | + * when the values are used.  'brot' is the number of bits the values in row 'b' | ||||||
|  | + * need to be rotated right to arrive at the correct values, and 'drot' | ||||||
|  | + * similarly for row 'd'.  (brot, drot) start out as (0, 0) but we make it such | ||||||
|  | + * that they end up as (25, 24) after every round. | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +	// ChaCha state registers | ||||||
|  | +	X0	.req	r0 | ||||||
|  | +	X1	.req	r1 | ||||||
|  | +	X2	.req	r2 | ||||||
|  | +	X3	.req	r3 | ||||||
|  | +	X4	.req	r4 | ||||||
|  | +	X5	.req	r5 | ||||||
|  | +	X6	.req	r6 | ||||||
|  | +	X7	.req	r7 | ||||||
|  | +	X8_X10	.req	r8	// shared by x8 and x10 | ||||||
|  | +	X9_X11	.req	r9	// shared by x9 and x11 | ||||||
|  | +	X12	.req	r10 | ||||||
|  | +	X13	.req	r11 | ||||||
|  | +	X14	.req	r12 | ||||||
|  | +	X15	.req	r14 | ||||||
|  | + | ||||||
|  | +.Lexpand_32byte_k: | ||||||
|  | +	// "expand 32-byte k" | ||||||
|  | +	.word	0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 | ||||||
|  | + | ||||||
|  | +#ifdef __thumb2__ | ||||||
|  | +#  define adrl adr | ||||||
|  | +#endif | ||||||
|  | + | ||||||
|  | +.macro __rev		out, in,  t0, t1, t2 | ||||||
|  | +.if __LINUX_ARM_ARCH__ >= 6 | ||||||
|  | +	rev		\out, \in | ||||||
|  | +.else | ||||||
|  | +	lsl		\t0, \in, #24 | ||||||
|  | +	and		\t1, \in, #0xff00 | ||||||
|  | +	and		\t2, \in, #0xff0000 | ||||||
|  | +	orr		\out, \t0, \in, lsr #24 | ||||||
|  | +	orr		\out, \out, \t1, lsl #8 | ||||||
|  | +	orr		\out, \out, \t2, lsr #8 | ||||||
|  | +.endif | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _le32_bswap	x,  t0, t1, t2 | ||||||
|  | +#ifdef __ARMEB__ | ||||||
|  | +	__rev		\x, \x,  \t0, \t1, \t2 | ||||||
|  | +#endif | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _le32_bswap_4x	a, b, c, d,  t0, t1, t2 | ||||||
|  | +	_le32_bswap	\a,  \t0, \t1, \t2 | ||||||
|  | +	_le32_bswap	\b,  \t0, \t1, \t2 | ||||||
|  | +	_le32_bswap	\c,  \t0, \t1, \t2 | ||||||
|  | +	_le32_bswap	\d,  \t0, \t1, \t2 | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro __ldrd		a, b, src, offset | ||||||
|  | +#if __LINUX_ARM_ARCH__ >= 6 | ||||||
|  | +	ldrd		\a, \b, [\src, #\offset] | ||||||
|  | +#else | ||||||
|  | +	ldr		\a, [\src, #\offset] | ||||||
|  | +	ldr		\b, [\src, #\offset + 4] | ||||||
|  | +#endif | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro __strd		a, b, dst, offset | ||||||
|  | +#if __LINUX_ARM_ARCH__ >= 6 | ||||||
|  | +	strd		\a, \b, [\dst, #\offset] | ||||||
|  | +#else | ||||||
|  | +	str		\a, [\dst, #\offset] | ||||||
|  | +	str		\b, [\dst, #\offset + 4] | ||||||
|  | +#endif | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _halfround	a1, b1, c1, d1,  a2, b2, c2, d2 | ||||||
|  | + | ||||||
|  | +	// a += b; d ^= a; d = rol(d, 16); | ||||||
|  | +	add		\a1, \a1, \b1, ror #brot | ||||||
|  | +	add		\a2, \a2, \b2, ror #brot | ||||||
|  | +	eor		\d1, \a1, \d1, ror #drot | ||||||
|  | +	eor		\d2, \a2, \d2, ror #drot | ||||||
|  | +	// drot == 32 - 16 == 16 | ||||||
|  | + | ||||||
|  | +	// c += d; b ^= c; b = rol(b, 12); | ||||||
|  | +	add		\c1, \c1, \d1, ror #16 | ||||||
|  | +	add		\c2, \c2, \d2, ror #16 | ||||||
|  | +	eor		\b1, \c1, \b1, ror #brot | ||||||
|  | +	eor		\b2, \c2, \b2, ror #brot | ||||||
|  | +	// brot == 32 - 12 == 20 | ||||||
|  | + | ||||||
|  | +	// a += b; d ^= a; d = rol(d, 8); | ||||||
|  | +	add		\a1, \a1, \b1, ror #20 | ||||||
|  | +	add		\a2, \a2, \b2, ror #20 | ||||||
|  | +	eor		\d1, \a1, \d1, ror #16 | ||||||
|  | +	eor		\d2, \a2, \d2, ror #16 | ||||||
|  | +	// drot == 32 - 8 == 24 | ||||||
|  | + | ||||||
|  | +	// c += d; b ^= c; b = rol(b, 7); | ||||||
|  | +	add		\c1, \c1, \d1, ror #24 | ||||||
|  | +	add		\c2, \c2, \d2, ror #24 | ||||||
|  | +	eor		\b1, \c1, \b1, ror #20 | ||||||
|  | +	eor		\b2, \c2, \b2, ror #20 | ||||||
|  | +	// brot == 32 - 7 == 25 | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _doubleround | ||||||
|  | + | ||||||
|  | +	// column round | ||||||
|  | + | ||||||
|  | +	// quarterrounds: (x0, x4, x8, x12) and (x1, x5, x9, x13) | ||||||
|  | +	_halfround	X0, X4, X8_X10, X12,  X1, X5, X9_X11, X13 | ||||||
|  | + | ||||||
|  | +	// save (x8, x9); restore (x10, x11) | ||||||
|  | +	__strd		X8_X10, X9_X11, sp, 0 | ||||||
|  | +	__ldrd		X8_X10, X9_X11, sp, 8 | ||||||
|  | + | ||||||
|  | +	// quarterrounds: (x2, x6, x10, x14) and (x3, x7, x11, x15) | ||||||
|  | +	_halfround	X2, X6, X8_X10, X14,  X3, X7, X9_X11, X15 | ||||||
|  | + | ||||||
|  | +	.set brot, 25 | ||||||
|  | +	.set drot, 24 | ||||||
|  | + | ||||||
|  | +	// diagonal round | ||||||
|  | + | ||||||
|  | +	// quarterrounds: (x0, x5, x10, x15) and (x1, x6, x11, x12) | ||||||
|  | +	_halfround	X0, X5, X8_X10, X15,  X1, X6, X9_X11, X12 | ||||||
|  | + | ||||||
|  | +	// save (x10, x11); restore (x8, x9) | ||||||
|  | +	__strd		X8_X10, X9_X11, sp, 8 | ||||||
|  | +	__ldrd		X8_X10, X9_X11, sp, 0 | ||||||
|  | + | ||||||
|  | +	// quarterrounds: (x2, x7, x8, x13) and (x3, x4, x9, x14) | ||||||
|  | +	_halfround	X2, X7, X8_X10, X13,  X3, X4, X9_X11, X14 | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _chacha_permute	nrounds | ||||||
|  | +	.set brot, 0 | ||||||
|  | +	.set drot, 0 | ||||||
|  | +	.rept \nrounds / 2 | ||||||
|  | +	 _doubleround | ||||||
|  | +	.endr | ||||||
|  | +.endm | ||||||
|  | + | ||||||
|  | +.macro _chacha		nrounds | ||||||
|  | + | ||||||
|  | +.Lnext_block\@: | ||||||
|  | +	// Stack: unused0-unused1 x10-x11 x0-x15 OUT IN LEN | ||||||
|  | +	// Registers contain x0-x9,x12-x15. | ||||||
|  | + | ||||||
|  | +	// Do the core ChaCha permutation to update x0-x15. | ||||||
|  | +	_chacha_permute	\nrounds | ||||||
|  | + | ||||||
|  | +	add		sp, #8 | ||||||
|  | +	// Stack: x10-x11 orig_x0-orig_x15 OUT IN LEN | ||||||
|  | +	// Registers contain x0-x9,x12-x15. | ||||||
|  | +	// x4-x7 are rotated by 'brot'; x12-x15 are rotated by 'drot'. | ||||||
|  | + | ||||||
|  | +	// Free up some registers (r8-r12,r14) by pushing (x8-x9,x12-x15). | ||||||
|  | +	push		{X8_X10, X9_X11, X12, X13, X14, X15} | ||||||
|  | + | ||||||
|  | +	// Load (OUT, IN, LEN). | ||||||
|  | +	ldr		r14, [sp, #96] | ||||||
|  | +	ldr		r12, [sp, #100] | ||||||
|  | +	ldr		r11, [sp, #104] | ||||||
|  | + | ||||||
|  | +	orr		r10, r14, r12 | ||||||
|  | + | ||||||
|  | +	// Use slow path if fewer than 64 bytes remain. | ||||||
|  | +	cmp		r11, #64 | ||||||
|  | +	blt		.Lxor_slowpath\@ | ||||||
|  | + | ||||||
|  | +	// Use slow path if IN and/or OUT isn't 4-byte aligned.  Needed even on | ||||||
|  | +	// ARMv6+, since ldmia and stmia (used below) still require alignment. | ||||||
|  | +	tst		r10, #3 | ||||||
|  | +	bne		.Lxor_slowpath\@ | ||||||
|  | + | ||||||
|  | +	// Fast path: XOR 64 bytes of aligned data. | ||||||
|  | + | ||||||
|  | +	// Stack: x8-x9 x12-x15 x10-x11 orig_x0-orig_x15 OUT IN LEN | ||||||
|  | +	// Registers: r0-r7 are x0-x7; r8-r11 are free; r12 is IN; r14 is OUT. | ||||||
|  | +	// x4-x7 are rotated by 'brot'; x12-x15 are rotated by 'drot'. | ||||||
|  | + | ||||||
|  | +	// x0-x3 | ||||||
|  | +	__ldrd		r8, r9, sp, 32 | ||||||
|  | +	__ldrd		r10, r11, sp, 40 | ||||||
|  | +	add		X0, X0, r8 | ||||||
|  | +	add		X1, X1, r9 | ||||||
|  | +	add		X2, X2, r10 | ||||||
|  | +	add		X3, X3, r11 | ||||||
|  | +	_le32_bswap_4x	X0, X1, X2, X3,  r8, r9, r10 | ||||||
|  | +	ldmia		r12!, {r8-r11} | ||||||
|  | +	eor		X0, X0, r8 | ||||||
|  | +	eor		X1, X1, r9 | ||||||
|  | +	eor		X2, X2, r10 | ||||||
|  | +	eor		X3, X3, r11 | ||||||
|  | +	stmia		r14!, {X0-X3} | ||||||
|  | + | ||||||
|  | +	// x4-x7 | ||||||
|  | +	__ldrd		r8, r9, sp, 48 | ||||||
|  | +	__ldrd		r10, r11, sp, 56 | ||||||
|  | +	add		X4, r8, X4, ror #brot | ||||||
|  | +	add		X5, r9, X5, ror #brot | ||||||
|  | +	ldmia		r12!, {X0-X3} | ||||||
|  | +	add		X6, r10, X6, ror #brot | ||||||
|  | +	add		X7, r11, X7, ror #brot | ||||||
|  | +	_le32_bswap_4x	X4, X5, X6, X7,  r8, r9, r10 | ||||||
|  | +	eor		X4, X4, X0 | ||||||
|  | +	eor		X5, X5, X1 | ||||||
|  | +	eor		X6, X6, X2 | ||||||
|  | +	eor		X7, X7, X3 | ||||||
|  | +	stmia		r14!, {X4-X7} | ||||||
|  | + | ||||||
|  | +	// x8-x15 | ||||||
|  | +	pop		{r0-r7}			// (x8-x9,x12-x15,x10-x11) | ||||||
|  | +	__ldrd		r8, r9, sp, 32 | ||||||
|  | +	__ldrd		r10, r11, sp, 40 | ||||||
|  | +	add		r0, r0, r8		// x8 | ||||||
|  | +	add		r1, r1, r9		// x9 | ||||||
|  | +	add		r6, r6, r10		// x10 | ||||||
|  | +	add		r7, r7, r11		// x11 | ||||||
|  | +	_le32_bswap_4x	r0, r1, r6, r7,  r8, r9, r10 | ||||||
|  | +	ldmia		r12!, {r8-r11} | ||||||
|  | +	eor		r0, r0, r8		// x8 | ||||||
|  | +	eor		r1, r1, r9		// x9 | ||||||
|  | +	eor		r6, r6, r10		// x10 | ||||||
|  | +	eor		r7, r7, r11		// x11 | ||||||
|  | +	stmia		r14!, {r0,r1,r6,r7} | ||||||
|  | +	ldmia		r12!, {r0,r1,r6,r7} | ||||||
|  | +	__ldrd		r8, r9, sp, 48 | ||||||
|  | +	__ldrd		r10, r11, sp, 56 | ||||||
|  | +	add		r2, r8, r2, ror #drot	// x12 | ||||||
|  | +	add		r3, r9, r3, ror #drot	// x13 | ||||||
|  | +	add		r4, r10, r4, ror #drot	// x14 | ||||||
|  | +	add		r5, r11, r5, ror #drot	// x15 | ||||||
|  | +	_le32_bswap_4x	r2, r3, r4, r5,  r9, r10, r11 | ||||||
|  | +	  ldr		r9, [sp, #72]		// load LEN | ||||||
|  | +	eor		r2, r2, r0		// x12 | ||||||
|  | +	eor		r3, r3, r1		// x13 | ||||||
|  | +	eor		r4, r4, r6		// x14 | ||||||
|  | +	eor		r5, r5, r7		// x15 | ||||||
|  | +	  subs		r9, #64			// decrement and check LEN | ||||||
|  | +	stmia		r14!, {r2-r5} | ||||||
|  | + | ||||||
|  | +	beq		.Ldone\@ | ||||||
|  | + | ||||||
|  | +.Lprepare_for_next_block\@: | ||||||
|  | + | ||||||
|  | +	// Stack: x0-x15 OUT IN LEN | ||||||
|  | + | ||||||
|  | +	// Increment block counter (x12) | ||||||
|  | +	add		r8, #1 | ||||||
|  | + | ||||||
|  | +	// Store updated (OUT, IN, LEN) | ||||||
|  | +	str		r14, [sp, #64] | ||||||
|  | +	str		r12, [sp, #68] | ||||||
|  | +	str		r9, [sp, #72] | ||||||
|  | + | ||||||
|  | +	  mov		r14, sp | ||||||
|  | + | ||||||
|  | +	// Store updated block counter (x12) | ||||||
|  | +	str		r8, [sp, #48] | ||||||
|  | + | ||||||
|  | +	  sub		sp, #16 | ||||||
|  | + | ||||||
|  | +	// Reload state and do next block | ||||||
|  | +	ldmia		r14!, {r0-r11}		// load x0-x11 | ||||||
|  | +	__strd		r10, r11, sp, 8		// store x10-x11 before state | ||||||
|  | +	ldmia		r14, {r10-r12,r14}	// load x12-x15 | ||||||
|  | +	b		.Lnext_block\@ | ||||||
|  | + | ||||||
|  | +.Lxor_slowpath\@: | ||||||
|  | +	// Slow path: < 64 bytes remaining, or unaligned input or output buffer. | ||||||
|  | +	// We handle it by storing the 64 bytes of keystream to the stack, then | ||||||
|  | +	// XOR-ing the needed portion with the data. | ||||||
|  | + | ||||||
|  | +	// Allocate keystream buffer | ||||||
|  | +	sub		sp, #64 | ||||||
|  | +	mov		r14, sp | ||||||
|  | + | ||||||
|  | +	// Stack: ks0-ks15 x8-x9 x12-x15 x10-x11 orig_x0-orig_x15 OUT IN LEN | ||||||
|  | +	// Registers: r0-r7 are x0-x7; r8-r11 are free; r12 is IN; r14 is &ks0. | ||||||
|  | +	// x4-x7 are rotated by 'brot'; x12-x15 are rotated by 'drot'. | ||||||
|  | + | ||||||
|  | +	// Save keystream for x0-x3 | ||||||
|  | +	__ldrd		r8, r9, sp, 96 | ||||||
|  | +	__ldrd		r10, r11, sp, 104 | ||||||
|  | +	add		X0, X0, r8 | ||||||
|  | +	add		X1, X1, r9 | ||||||
|  | +	add		X2, X2, r10 | ||||||
|  | +	add		X3, X3, r11 | ||||||
|  | +	_le32_bswap_4x	X0, X1, X2, X3,  r8, r9, r10 | ||||||
|  | +	stmia		r14!, {X0-X3} | ||||||
|  | + | ||||||
|  | +	// Save keystream for x4-x7 | ||||||
|  | +	__ldrd		r8, r9, sp, 112 | ||||||
|  | +	__ldrd		r10, r11, sp, 120 | ||||||
|  | +	add		X4, r8, X4, ror #brot | ||||||
|  | +	add		X5, r9, X5, ror #brot | ||||||
|  | +	add		X6, r10, X6, ror #brot | ||||||
|  | +	add		X7, r11, X7, ror #brot | ||||||
|  | +	_le32_bswap_4x	X4, X5, X6, X7,  r8, r9, r10 | ||||||
|  | +	  add		r8, sp, #64 | ||||||
|  | +	stmia		r14!, {X4-X7} | ||||||
|  | + | ||||||
|  | +	// Save keystream for x8-x15 | ||||||
|  | +	ldm		r8, {r0-r7}		// (x8-x9,x12-x15,x10-x11) | ||||||
|  | +	__ldrd		r8, r9, sp, 128 | ||||||
|  | +	__ldrd		r10, r11, sp, 136 | ||||||
|  | +	add		r0, r0, r8		// x8 | ||||||
|  | +	add		r1, r1, r9		// x9 | ||||||
|  | +	add		r6, r6, r10		// x10 | ||||||
|  | +	add		r7, r7, r11		// x11 | ||||||
|  | +	_le32_bswap_4x	r0, r1, r6, r7,  r8, r9, r10 | ||||||
|  | +	stmia		r14!, {r0,r1,r6,r7} | ||||||
|  | +	__ldrd		r8, r9, sp, 144 | ||||||
|  | +	__ldrd		r10, r11, sp, 152 | ||||||
|  | +	add		r2, r8, r2, ror #drot	// x12 | ||||||
|  | +	add		r3, r9, r3, ror #drot	// x13 | ||||||
|  | +	add		r4, r10, r4, ror #drot	// x14 | ||||||
|  | +	add		r5, r11, r5, ror #drot	// x15 | ||||||
|  | +	_le32_bswap_4x	r2, r3, r4, r5,  r9, r10, r11 | ||||||
|  | +	stmia		r14, {r2-r5} | ||||||
|  | + | ||||||
|  | +	// Stack: ks0-ks15 unused0-unused7 x0-x15 OUT IN LEN | ||||||
|  | +	// Registers: r8 is block counter, r12 is IN. | ||||||
|  | + | ||||||
|  | +	ldr		r9, [sp, #168]		// LEN | ||||||
|  | +	ldr		r14, [sp, #160]		// OUT | ||||||
|  | +	cmp		r9, #64 | ||||||
|  | +	  mov		r0, sp | ||||||
|  | +	movle		r1, r9 | ||||||
|  | +	movgt		r1, #64 | ||||||
|  | +	// r1 is number of bytes to XOR, in range [1, 64] | ||||||
|  | + | ||||||
|  | +.if __LINUX_ARM_ARCH__ < 6 | ||||||
|  | +	orr		r2, r12, r14 | ||||||
|  | +	tst		r2, #3			// IN or OUT misaligned? | ||||||
|  | +	bne		.Lxor_next_byte\@ | ||||||
|  | +.endif | ||||||
|  | + | ||||||
|  | +	// XOR a word at a time | ||||||
|  | +.rept 16 | ||||||
|  | +	subs		r1, #4 | ||||||
|  | +	blt		.Lxor_words_done\@ | ||||||
|  | +	ldr		r2, [r12], #4 | ||||||
|  | +	ldr		r3, [r0], #4 | ||||||
|  | +	eor		r2, r2, r3 | ||||||
|  | +	str		r2, [r14], #4 | ||||||
|  | +.endr | ||||||
|  | +	b		.Lxor_slowpath_done\@ | ||||||
|  | +.Lxor_words_done\@: | ||||||
|  | +	ands		r1, r1, #3 | ||||||
|  | +	beq		.Lxor_slowpath_done\@ | ||||||
|  | + | ||||||
|  | +	// XOR a byte at a time | ||||||
|  | +.Lxor_next_byte\@: | ||||||
|  | +	ldrb		r2, [r12], #1 | ||||||
|  | +	ldrb		r3, [r0], #1 | ||||||
|  | +	eor		r2, r2, r3 | ||||||
|  | +	strb		r2, [r14], #1 | ||||||
|  | +	subs		r1, #1 | ||||||
|  | +	bne		.Lxor_next_byte\@ | ||||||
|  | + | ||||||
|  | +.Lxor_slowpath_done\@: | ||||||
|  | +	subs		r9, #64 | ||||||
|  | +	add		sp, #96 | ||||||
|  | +	bgt		.Lprepare_for_next_block\@ | ||||||
|  | + | ||||||
|  | +.Ldone\@: | ||||||
|  | +.endm	// _chacha | ||||||
|  | + | ||||||
|  | +/* | ||||||
|  | + * void chacha20_arm(u8 *out, const u8 *in, size_t len, const u32 key[8], | ||||||
|  | + *		     const u32 iv[4]); | ||||||
|  | + */ | ||||||
|  | +ENTRY(chacha20_arm) | ||||||
|  | +	cmp		r2, #0			// len == 0? | ||||||
|  | +	reteq		lr | ||||||
|  | + | ||||||
|  | +	push		{r0-r2,r4-r11,lr} | ||||||
|  | + | ||||||
|  | +	// Push state x0-x15 onto stack. | ||||||
|  | +	// Also store an extra copy of x10-x11 just before the state. | ||||||
|  | + | ||||||
|  | +	ldr		r4, [sp, #48]		// iv | ||||||
|  | +	mov		r0, sp | ||||||
|  | +	sub		sp, #80 | ||||||
|  | + | ||||||
|  | +	// iv: x12-x15 | ||||||
|  | +	ldm		r4, {X12,X13,X14,X15} | ||||||
|  | +	stmdb		r0!, {X12,X13,X14,X15} | ||||||
|  | + | ||||||
|  | +	// key: x4-x11 | ||||||
|  | +	__ldrd		X8_X10, X9_X11, r3, 24 | ||||||
|  | +	__strd		X8_X10, X9_X11, sp, 8 | ||||||
|  | +	stmdb		r0!, {X8_X10, X9_X11} | ||||||
|  | +	ldm		r3, {X4-X9_X11} | ||||||
|  | +	stmdb		r0!, {X4-X9_X11} | ||||||
|  | + | ||||||
|  | +	// constants: x0-x3 | ||||||
|  | +	adrl		X3, .Lexpand_32byte_k | ||||||
|  | +	ldm		X3, {X0-X3} | ||||||
|  | +	__strd		X0, X1, sp, 16 | ||||||
|  | +	__strd		X2, X3, sp, 24 | ||||||
|  | + | ||||||
|  | +	_chacha		20 | ||||||
|  | + | ||||||
|  | +	add		sp, #76 | ||||||
|  | +	pop		{r4-r11, pc} | ||||||
|  | +ENDPROC(chacha20_arm) | ||||||
|  | + | ||||||
|  | +/* | ||||||
|  | + * void hchacha20_arm(const u32 state[16], u32 out[8]); | ||||||
|  | + */ | ||||||
|  | +ENTRY(hchacha20_arm) | ||||||
|  | +	push		{r1,r4-r11,lr} | ||||||
|  | + | ||||||
|  | +	mov		r14, r0 | ||||||
|  | +	ldmia		r14!, {r0-r11}		// load x0-x11 | ||||||
|  | +	push		{r10-r11}		// store x10-x11 to stack | ||||||
|  | +	ldm		r14, {r10-r12,r14}	// load x12-x15 | ||||||
|  | +	sub		sp, #8 | ||||||
|  | + | ||||||
|  | +	_chacha_permute	20 | ||||||
|  | + | ||||||
|  | +	// Skip over (unused0-unused1, x10-x11) | ||||||
|  | +	add		sp, #16 | ||||||
|  | + | ||||||
|  | +	// Fix up rotations of x12-x15 | ||||||
|  | +	ror		X12, X12, #drot | ||||||
|  | +	ror		X13, X13, #drot | ||||||
|  | +	  pop		{r4}			// load 'out' | ||||||
|  | +	ror		X14, X14, #drot | ||||||
|  | +	ror		X15, X15, #drot | ||||||
|  | + | ||||||
|  | +	// Store (x0-x3,x12-x15) to 'out' | ||||||
|  | +	stm		r4, {X0,X1,X2,X3,X12,X13,X14,X15} | ||||||
|  | + | ||||||
|  | +	pop		{r4-r11,pc} | ||||||
|  | +ENDPROC(hchacha20_arm) | ||||||
| @@ -0,0 +1,691 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:14 +0100 | ||||||
|  | Subject: [PATCH] crypto: arm/chacha - remove dependency on generic ChaCha | ||||||
|  |  driver | ||||||
|  |  | ||||||
|  | commit b36d8c09e710c71f6a9690b6586fea2d1c9e1e27 upstream. | ||||||
|  |  | ||||||
|  | Instead of falling back to the generic ChaCha skcipher driver for | ||||||
|  | non-SIMD cases, use a fast scalar implementation for ARM authored | ||||||
|  | by Eric Biggers. This removes the module dependency on chacha-generic | ||||||
|  | altogether, which also simplifies things when we expose the ChaCha | ||||||
|  | library interface from this module. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm/crypto/Kconfig              |   4 +- | ||||||
|  |  arch/arm/crypto/Makefile             |   3 +- | ||||||
|  |  arch/arm/crypto/chacha-glue.c        | 304 +++++++++++++++++++++++++++ | ||||||
|  |  arch/arm/crypto/chacha-neon-glue.c   | 202 ------------------ | ||||||
|  |  arch/arm/crypto/chacha-scalar-core.S |  65 +++--- | ||||||
|  |  arch/arm64/crypto/chacha-neon-glue.c |   2 +- | ||||||
|  |  6 files changed, 340 insertions(+), 240 deletions(-) | ||||||
|  |  create mode 100644 arch/arm/crypto/chacha-glue.c | ||||||
|  |  delete mode 100644 arch/arm/crypto/chacha-neon-glue.c | ||||||
|  |  | ||||||
|  | --- a/arch/arm/crypto/Kconfig | ||||||
|  | +++ b/arch/arm/crypto/Kconfig | ||||||
|  | @@ -127,10 +127,8 @@ config CRYPTO_CRC32_ARM_CE | ||||||
|  |  	select CRYPTO_HASH | ||||||
|  |   | ||||||
|  |  config CRYPTO_CHACHA20_NEON | ||||||
|  | -	tristate "NEON accelerated ChaCha stream cipher algorithms" | ||||||
|  | -	depends on KERNEL_MODE_NEON | ||||||
|  | +	tristate "NEON and scalar accelerated ChaCha stream cipher algorithms" | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  | -	select CRYPTO_CHACHA20 | ||||||
|  |   | ||||||
|  |  config CRYPTO_NHPOLY1305_NEON | ||||||
|  |  	tristate "NEON accelerated NHPoly1305 hash function (for Adiantum)" | ||||||
|  | --- a/arch/arm/crypto/Makefile | ||||||
|  | +++ b/arch/arm/crypto/Makefile | ||||||
|  | @@ -53,7 +53,8 @@ aes-arm-ce-y	:= aes-ce-core.o aes-ce-glu | ||||||
|  |  ghash-arm-ce-y	:= ghash-ce-core.o ghash-ce-glue.o | ||||||
|  |  crct10dif-arm-ce-y	:= crct10dif-ce-core.o crct10dif-ce-glue.o | ||||||
|  |  crc32-arm-ce-y:= crc32-ce-core.o crc32-ce-glue.o | ||||||
|  | -chacha-neon-y := chacha-neon-core.o chacha-neon-glue.o | ||||||
|  | +chacha-neon-y := chacha-scalar-core.o chacha-glue.o | ||||||
|  | +chacha-neon-$(CONFIG_KERNEL_MODE_NEON) += chacha-neon-core.o | ||||||
|  |  nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o | ||||||
|  |   | ||||||
|  |  ifdef REGENERATE_ARM_CRYPTO | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/arch/arm/crypto/chacha-glue.c | ||||||
|  | @@ -0,0 +1,304 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0 | ||||||
|  | +/* | ||||||
|  | + * ARM NEON accelerated ChaCha and XChaCha stream ciphers, | ||||||
|  | + * including ChaCha20 (RFC7539) | ||||||
|  | + * | ||||||
|  | + * Copyright (C) 2016-2019 Linaro, Ltd. <ard.biesheuvel@linaro.org> | ||||||
|  | + * Copyright (C) 2015 Martin Willi | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <crypto/algapi.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  | +#include <crypto/internal/simd.h> | ||||||
|  | +#include <crypto/internal/skcipher.h> | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | +#include <linux/module.h> | ||||||
|  | + | ||||||
|  | +#include <asm/cputype.h> | ||||||
|  | +#include <asm/hwcap.h> | ||||||
|  | +#include <asm/neon.h> | ||||||
|  | +#include <asm/simd.h> | ||||||
|  | + | ||||||
|  | +asmlinkage void chacha_block_xor_neon(const u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +				      int nrounds); | ||||||
|  | +asmlinkage void chacha_4block_xor_neon(const u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +				       int nrounds); | ||||||
|  | +asmlinkage void hchacha_block_arm(const u32 *state, u32 *out, int nrounds); | ||||||
|  | +asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds); | ||||||
|  | + | ||||||
|  | +asmlinkage void chacha_doarm(u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  | +			     const u32 *state, int nrounds); | ||||||
|  | + | ||||||
|  | +static inline bool neon_usable(void) | ||||||
|  | +{ | ||||||
|  | +	return crypto_simd_usable(); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +			  unsigned int bytes, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	u8 buf[CHACHA_BLOCK_SIZE]; | ||||||
|  | + | ||||||
|  | +	while (bytes >= CHACHA_BLOCK_SIZE * 4) { | ||||||
|  | +		chacha_4block_xor_neon(state, dst, src, nrounds); | ||||||
|  | +		bytes -= CHACHA_BLOCK_SIZE * 4; | ||||||
|  | +		src += CHACHA_BLOCK_SIZE * 4; | ||||||
|  | +		dst += CHACHA_BLOCK_SIZE * 4; | ||||||
|  | +		state[12] += 4; | ||||||
|  | +	} | ||||||
|  | +	while (bytes >= CHACHA_BLOCK_SIZE) { | ||||||
|  | +		chacha_block_xor_neon(state, dst, src, nrounds); | ||||||
|  | +		bytes -= CHACHA_BLOCK_SIZE; | ||||||
|  | +		src += CHACHA_BLOCK_SIZE; | ||||||
|  | +		dst += CHACHA_BLOCK_SIZE; | ||||||
|  | +		state[12]++; | ||||||
|  | +	} | ||||||
|  | +	if (bytes) { | ||||||
|  | +		memcpy(buf, src, bytes); | ||||||
|  | +		chacha_block_xor_neon(state, buf, buf, nrounds); | ||||||
|  | +		memcpy(dst, buf, bytes); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int chacha_stream_xor(struct skcipher_request *req, | ||||||
|  | +			     const struct chacha_ctx *ctx, const u8 *iv, | ||||||
|  | +			     bool neon) | ||||||
|  | +{ | ||||||
|  | +	struct skcipher_walk walk; | ||||||
|  | +	u32 state[16]; | ||||||
|  | +	int err; | ||||||
|  | + | ||||||
|  | +	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  | + | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  | + | ||||||
|  | +	while (walk.nbytes > 0) { | ||||||
|  | +		unsigned int nbytes = walk.nbytes; | ||||||
|  | + | ||||||
|  | +		if (nbytes < walk.total) | ||||||
|  | +			nbytes = round_down(nbytes, walk.stride); | ||||||
|  | + | ||||||
|  | +		if (!neon) { | ||||||
|  | +			chacha_doarm(walk.dst.virt.addr, walk.src.virt.addr, | ||||||
|  | +				     nbytes, state, ctx->nrounds); | ||||||
|  | +			state[12] += DIV_ROUND_UP(nbytes, CHACHA_BLOCK_SIZE); | ||||||
|  | +		} else { | ||||||
|  | +			kernel_neon_begin(); | ||||||
|  | +			chacha_doneon(state, walk.dst.virt.addr, | ||||||
|  | +				      walk.src.virt.addr, nbytes, ctx->nrounds); | ||||||
|  | +			kernel_neon_end(); | ||||||
|  | +		} | ||||||
|  | +		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  | +	} | ||||||
|  | + | ||||||
|  | +	return err; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int do_chacha(struct skcipher_request *req, bool neon) | ||||||
|  | +{ | ||||||
|  | +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | +	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | + | ||||||
|  | +	return chacha_stream_xor(req, ctx, req->iv, neon); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int chacha_arm(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	return do_chacha(req, false); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int chacha_neon(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	return do_chacha(req, neon_usable()); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int do_xchacha(struct skcipher_request *req, bool neon) | ||||||
|  | +{ | ||||||
|  | +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | +	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | +	struct chacha_ctx subctx; | ||||||
|  | +	u32 state[16]; | ||||||
|  | +	u8 real_iv[16]; | ||||||
|  | + | ||||||
|  | +	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  | + | ||||||
|  | +	if (!neon) { | ||||||
|  | +		hchacha_block_arm(state, subctx.key, ctx->nrounds); | ||||||
|  | +	} else { | ||||||
|  | +		kernel_neon_begin(); | ||||||
|  | +		hchacha_block_neon(state, subctx.key, ctx->nrounds); | ||||||
|  | +		kernel_neon_end(); | ||||||
|  | +	} | ||||||
|  | +	subctx.nrounds = ctx->nrounds; | ||||||
|  | + | ||||||
|  | +	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  | +	memcpy(&real_iv[8], req->iv + 16, 8); | ||||||
|  | +	return chacha_stream_xor(req, &subctx, real_iv, neon); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int xchacha_arm(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	return do_xchacha(req, false); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int xchacha_neon(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	return do_xchacha(req, neon_usable()); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static struct skcipher_alg arm_algs[] = { | ||||||
|  | +	{ | ||||||
|  | +		.base.cra_name		= "chacha20", | ||||||
|  | +		.base.cra_driver_name	= "chacha20-arm", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= chacha_arm, | ||||||
|  | +		.decrypt		= chacha_arm, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha20", | ||||||
|  | +		.base.cra_driver_name	= "xchacha20-arm", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= xchacha_arm, | ||||||
|  | +		.decrypt		= xchacha_arm, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha12", | ||||||
|  | +		.base.cra_driver_name	= "xchacha12-arm", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha12_setkey, | ||||||
|  | +		.encrypt		= xchacha_arm, | ||||||
|  | +		.decrypt		= xchacha_arm, | ||||||
|  | +	}, | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +static struct skcipher_alg neon_algs[] = { | ||||||
|  | +	{ | ||||||
|  | +		.base.cra_name		= "chacha20", | ||||||
|  | +		.base.cra_driver_name	= "chacha20-neon", | ||||||
|  | +		.base.cra_priority	= 300, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= chacha_neon, | ||||||
|  | +		.decrypt		= chacha_neon, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha20", | ||||||
|  | +		.base.cra_driver_name	= "xchacha20-neon", | ||||||
|  | +		.base.cra_priority	= 300, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= xchacha_neon, | ||||||
|  | +		.decrypt		= xchacha_neon, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha12", | ||||||
|  | +		.base.cra_driver_name	= "xchacha12-neon", | ||||||
|  | +		.base.cra_priority	= 300, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha12_setkey, | ||||||
|  | +		.encrypt		= xchacha_neon, | ||||||
|  | +		.decrypt		= xchacha_neon, | ||||||
|  | +	} | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +static int __init chacha_simd_mod_init(void) | ||||||
|  | +{ | ||||||
|  | +	int err; | ||||||
|  | + | ||||||
|  | +	err = crypto_register_skciphers(arm_algs, ARRAY_SIZE(arm_algs)); | ||||||
|  | +	if (err) | ||||||
|  | +		return err; | ||||||
|  | + | ||||||
|  | +	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON)) { | ||||||
|  | +		int i; | ||||||
|  | + | ||||||
|  | +		switch (read_cpuid_part()) { | ||||||
|  | +		case ARM_CPU_PART_CORTEX_A7: | ||||||
|  | +		case ARM_CPU_PART_CORTEX_A5: | ||||||
|  | +			/* | ||||||
|  | +			 * The Cortex-A7 and Cortex-A5 do not perform well with | ||||||
|  | +			 * the NEON implementation but do incredibly with the | ||||||
|  | +			 * scalar one and use less power. | ||||||
|  | +			 */ | ||||||
|  | +			for (i = 0; i < ARRAY_SIZE(neon_algs); i++) | ||||||
|  | +				neon_algs[i].base.cra_priority = 0; | ||||||
|  | +			break; | ||||||
|  | +		} | ||||||
|  | + | ||||||
|  | +		err = crypto_register_skciphers(neon_algs, ARRAY_SIZE(neon_algs)); | ||||||
|  | +		if (err) | ||||||
|  | +			crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs)); | ||||||
|  | +	} | ||||||
|  | +	return err; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static void __exit chacha_simd_mod_fini(void) | ||||||
|  | +{ | ||||||
|  | +	crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs)); | ||||||
|  | +	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON)) | ||||||
|  | +		crypto_unregister_skciphers(neon_algs, ARRAY_SIZE(neon_algs)); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +module_init(chacha_simd_mod_init); | ||||||
|  | +module_exit(chacha_simd_mod_fini); | ||||||
|  | + | ||||||
|  | +MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (scalar and NEON accelerated)"); | ||||||
|  | +MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); | ||||||
|  | +MODULE_LICENSE("GPL v2"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("chacha20"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("chacha20-arm"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha20"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha20-arm"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha12"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha12-arm"); | ||||||
|  | +#ifdef CONFIG_KERNEL_MODE_NEON | ||||||
|  | +MODULE_ALIAS_CRYPTO("chacha20-neon"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha20-neon"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha12-neon"); | ||||||
|  | +#endif | ||||||
|  | --- a/arch/arm/crypto/chacha-neon-glue.c | ||||||
|  | +++ /dev/null | ||||||
|  | @@ -1,202 +0,0 @@ | ||||||
|  | -/* | ||||||
|  | - * ARM NEON accelerated ChaCha and XChaCha stream ciphers, | ||||||
|  | - * including ChaCha20 (RFC7539) | ||||||
|  | - * | ||||||
|  | - * Copyright (C) 2016 Linaro, Ltd. <ard.biesheuvel@linaro.org> | ||||||
|  | - * | ||||||
|  | - * This program is free software; you can redistribute it and/or modify | ||||||
|  | - * it under the terms of the GNU General Public License version 2 as | ||||||
|  | - * published by the Free Software Foundation. | ||||||
|  | - * | ||||||
|  | - * Based on: | ||||||
|  | - * ChaCha20 256-bit cipher algorithm, RFC7539, SIMD glue code | ||||||
|  | - * | ||||||
|  | - * Copyright (C) 2015 Martin Willi | ||||||
|  | - * | ||||||
|  | - * This program is free software; you can redistribute it and/or modify | ||||||
|  | - * it under the terms of the GNU General Public License as published by | ||||||
|  | - * the Free Software Foundation; either version 2 of the License, or | ||||||
|  | - * (at your option) any later version. | ||||||
|  | - */ | ||||||
|  | - | ||||||
|  | -#include <crypto/algapi.h> | ||||||
|  | -#include <crypto/internal/chacha.h> | ||||||
|  | -#include <crypto/internal/simd.h> | ||||||
|  | -#include <crypto/internal/skcipher.h> | ||||||
|  | -#include <linux/kernel.h> | ||||||
|  | -#include <linux/module.h> | ||||||
|  | - | ||||||
|  | -#include <asm/hwcap.h> | ||||||
|  | -#include <asm/neon.h> | ||||||
|  | -#include <asm/simd.h> | ||||||
|  | - | ||||||
|  | -asmlinkage void chacha_block_xor_neon(const u32 *state, u8 *dst, const u8 *src, | ||||||
|  | -				      int nrounds); | ||||||
|  | -asmlinkage void chacha_4block_xor_neon(const u32 *state, u8 *dst, const u8 *src, | ||||||
|  | -				       int nrounds); | ||||||
|  | -asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds); | ||||||
|  | - | ||||||
|  | -static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | -			  unsigned int bytes, int nrounds) | ||||||
|  | -{ | ||||||
|  | -	u8 buf[CHACHA_BLOCK_SIZE]; | ||||||
|  | - | ||||||
|  | -	while (bytes >= CHACHA_BLOCK_SIZE * 4) { | ||||||
|  | -		chacha_4block_xor_neon(state, dst, src, nrounds); | ||||||
|  | -		bytes -= CHACHA_BLOCK_SIZE * 4; | ||||||
|  | -		src += CHACHA_BLOCK_SIZE * 4; | ||||||
|  | -		dst += CHACHA_BLOCK_SIZE * 4; | ||||||
|  | -		state[12] += 4; | ||||||
|  | -	} | ||||||
|  | -	while (bytes >= CHACHA_BLOCK_SIZE) { | ||||||
|  | -		chacha_block_xor_neon(state, dst, src, nrounds); | ||||||
|  | -		bytes -= CHACHA_BLOCK_SIZE; | ||||||
|  | -		src += CHACHA_BLOCK_SIZE; | ||||||
|  | -		dst += CHACHA_BLOCK_SIZE; | ||||||
|  | -		state[12]++; | ||||||
|  | -	} | ||||||
|  | -	if (bytes) { | ||||||
|  | -		memcpy(buf, src, bytes); | ||||||
|  | -		chacha_block_xor_neon(state, buf, buf, nrounds); | ||||||
|  | -		memcpy(dst, buf, bytes); | ||||||
|  | -	} | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static int chacha_neon_stream_xor(struct skcipher_request *req, | ||||||
|  | -				  const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  | -{ | ||||||
|  | -	struct skcipher_walk walk; | ||||||
|  | -	u32 state[16]; | ||||||
|  | -	int err; | ||||||
|  | - | ||||||
|  | -	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  | - | ||||||
|  | -	crypto_chacha_init(state, ctx, iv); | ||||||
|  | - | ||||||
|  | -	while (walk.nbytes > 0) { | ||||||
|  | -		unsigned int nbytes = walk.nbytes; | ||||||
|  | - | ||||||
|  | -		if (nbytes < walk.total) | ||||||
|  | -			nbytes = round_down(nbytes, walk.stride); | ||||||
|  | - | ||||||
|  | -		kernel_neon_begin(); | ||||||
|  | -		chacha_doneon(state, walk.dst.virt.addr, walk.src.virt.addr, | ||||||
|  | -			      nbytes, ctx->nrounds); | ||||||
|  | -		kernel_neon_end(); | ||||||
|  | -		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  | -	} | ||||||
|  | - | ||||||
|  | -	return err; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static int chacha_neon(struct skcipher_request *req) | ||||||
|  | -{ | ||||||
|  | -	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | -	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | - | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_chacha_crypt(req); | ||||||
|  | - | ||||||
|  | -	return chacha_neon_stream_xor(req, ctx, req->iv); | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static int xchacha_neon(struct skcipher_request *req) | ||||||
|  | -{ | ||||||
|  | -	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | -	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | -	struct chacha_ctx subctx; | ||||||
|  | -	u32 state[16]; | ||||||
|  | -	u8 real_iv[16]; | ||||||
|  | - | ||||||
|  | -	if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) | ||||||
|  | -		return crypto_xchacha_crypt(req); | ||||||
|  | - | ||||||
|  | -	crypto_chacha_init(state, ctx, req->iv); | ||||||
|  | - | ||||||
|  | -	kernel_neon_begin(); | ||||||
|  | -	hchacha_block_neon(state, subctx.key, ctx->nrounds); | ||||||
|  | -	kernel_neon_end(); | ||||||
|  | -	subctx.nrounds = ctx->nrounds; | ||||||
|  | - | ||||||
|  | -	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  | -	memcpy(&real_iv[8], req->iv + 16, 8); | ||||||
|  | -	return chacha_neon_stream_xor(req, &subctx, real_iv); | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static struct skcipher_alg algs[] = { | ||||||
|  | -	{ | ||||||
|  | -		.base.cra_name		= "chacha20", | ||||||
|  | -		.base.cra_driver_name	= "chacha20-neon", | ||||||
|  | -		.base.cra_priority	= 300, | ||||||
|  | -		.base.cra_blocksize	= 1, | ||||||
|  | -		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | -		.base.cra_module	= THIS_MODULE, | ||||||
|  | - | ||||||
|  | -		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  | -		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | -		.encrypt		= chacha_neon, | ||||||
|  | -		.decrypt		= chacha_neon, | ||||||
|  | -	}, { | ||||||
|  | -		.base.cra_name		= "xchacha20", | ||||||
|  | -		.base.cra_driver_name	= "xchacha20-neon", | ||||||
|  | -		.base.cra_priority	= 300, | ||||||
|  | -		.base.cra_blocksize	= 1, | ||||||
|  | -		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | -		.base.cra_module	= THIS_MODULE, | ||||||
|  | - | ||||||
|  | -		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | -		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha20_setkey, | ||||||
|  | -		.encrypt		= xchacha_neon, | ||||||
|  | -		.decrypt		= xchacha_neon, | ||||||
|  | -	}, { | ||||||
|  | -		.base.cra_name		= "xchacha12", | ||||||
|  | -		.base.cra_driver_name	= "xchacha12-neon", | ||||||
|  | -		.base.cra_priority	= 300, | ||||||
|  | -		.base.cra_blocksize	= 1, | ||||||
|  | -		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | -		.base.cra_module	= THIS_MODULE, | ||||||
|  | - | ||||||
|  | -		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | -		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | -		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | -		.walksize		= 4 * CHACHA_BLOCK_SIZE, | ||||||
|  | -		.setkey			= crypto_chacha12_setkey, | ||||||
|  | -		.encrypt		= xchacha_neon, | ||||||
|  | -		.decrypt		= xchacha_neon, | ||||||
|  | -	} | ||||||
|  | -}; | ||||||
|  | - | ||||||
|  | -static int __init chacha_simd_mod_init(void) | ||||||
|  | -{ | ||||||
|  | -	if (!(elf_hwcap & HWCAP_NEON)) | ||||||
|  | -		return -ENODEV; | ||||||
|  | - | ||||||
|  | -	return crypto_register_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static void __exit chacha_simd_mod_fini(void) | ||||||
|  | -{ | ||||||
|  | -	crypto_unregister_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -module_init(chacha_simd_mod_init); | ||||||
|  | -module_exit(chacha_simd_mod_fini); | ||||||
|  | - | ||||||
|  | -MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (NEON accelerated)"); | ||||||
|  | -MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); | ||||||
|  | -MODULE_LICENSE("GPL v2"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("chacha20"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("chacha20-neon"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("xchacha20"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("xchacha20-neon"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("xchacha12"); | ||||||
|  | -MODULE_ALIAS_CRYPTO("xchacha12-neon"); | ||||||
|  | --- a/arch/arm/crypto/chacha-scalar-core.S | ||||||
|  | +++ b/arch/arm/crypto/chacha-scalar-core.S | ||||||
|  | @@ -41,14 +41,6 @@ | ||||||
|  |  	X14	.req	r12 | ||||||
|  |  	X15	.req	r14 | ||||||
|  |   | ||||||
|  | -.Lexpand_32byte_k: | ||||||
|  | -	// "expand 32-byte k" | ||||||
|  | -	.word	0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 | ||||||
|  | - | ||||||
|  | -#ifdef __thumb2__ | ||||||
|  | -#  define adrl adr | ||||||
|  | -#endif | ||||||
|  | - | ||||||
|  |  .macro __rev		out, in,  t0, t1, t2 | ||||||
|  |  .if __LINUX_ARM_ARCH__ >= 6 | ||||||
|  |  	rev		\out, \in | ||||||
|  | @@ -391,61 +383,65 @@ | ||||||
|  |  .endm	// _chacha | ||||||
|  |   | ||||||
|  |  /* | ||||||
|  | - * void chacha20_arm(u8 *out, const u8 *in, size_t len, const u32 key[8], | ||||||
|  | - *		     const u32 iv[4]); | ||||||
|  | + * void chacha_doarm(u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  | + *		     const u32 *state, int nrounds); | ||||||
|  |   */ | ||||||
|  | -ENTRY(chacha20_arm) | ||||||
|  | +ENTRY(chacha_doarm) | ||||||
|  |  	cmp		r2, #0			// len == 0? | ||||||
|  |  	reteq		lr | ||||||
|  |   | ||||||
|  | +	ldr		ip, [sp] | ||||||
|  | +	cmp		ip, #12 | ||||||
|  | + | ||||||
|  |  	push		{r0-r2,r4-r11,lr} | ||||||
|  |   | ||||||
|  |  	// Push state x0-x15 onto stack. | ||||||
|  |  	// Also store an extra copy of x10-x11 just before the state. | ||||||
|  |   | ||||||
|  | -	ldr		r4, [sp, #48]		// iv | ||||||
|  | -	mov		r0, sp | ||||||
|  | -	sub		sp, #80 | ||||||
|  | - | ||||||
|  | -	// iv: x12-x15 | ||||||
|  | -	ldm		r4, {X12,X13,X14,X15} | ||||||
|  | -	stmdb		r0!, {X12,X13,X14,X15} | ||||||
|  | +	add		X12, r3, #48 | ||||||
|  | +	ldm		X12, {X12,X13,X14,X15} | ||||||
|  | +	push		{X12,X13,X14,X15} | ||||||
|  | +	sub		sp, sp, #64 | ||||||
|  |   | ||||||
|  | -	// key: x4-x11 | ||||||
|  | -	__ldrd		X8_X10, X9_X11, r3, 24 | ||||||
|  | +	__ldrd		X8_X10, X9_X11, r3, 40 | ||||||
|  |  	__strd		X8_X10, X9_X11, sp, 8 | ||||||
|  | -	stmdb		r0!, {X8_X10, X9_X11} | ||||||
|  | -	ldm		r3, {X4-X9_X11} | ||||||
|  | -	stmdb		r0!, {X4-X9_X11} | ||||||
|  | - | ||||||
|  | -	// constants: x0-x3 | ||||||
|  | -	adrl		X3, .Lexpand_32byte_k | ||||||
|  | -	ldm		X3, {X0-X3} | ||||||
|  | +	__strd		X8_X10, X9_X11, sp, 56 | ||||||
|  | +	ldm		r3, {X0-X9_X11} | ||||||
|  |  	__strd		X0, X1, sp, 16 | ||||||
|  |  	__strd		X2, X3, sp, 24 | ||||||
|  | +	__strd		X4, X5, sp, 32 | ||||||
|  | +	__strd		X6, X7, sp, 40 | ||||||
|  | +	__strd		X8_X10, X9_X11, sp, 48 | ||||||
|  |   | ||||||
|  | +	beq		1f | ||||||
|  |  	_chacha		20 | ||||||
|  |   | ||||||
|  | -	add		sp, #76 | ||||||
|  | +0:	add		sp, #76 | ||||||
|  |  	pop		{r4-r11, pc} | ||||||
|  | -ENDPROC(chacha20_arm) | ||||||
|  | + | ||||||
|  | +1:	_chacha		12 | ||||||
|  | +	b		0b | ||||||
|  | +ENDPROC(chacha_doarm) | ||||||
|  |   | ||||||
|  |  /* | ||||||
|  | - * void hchacha20_arm(const u32 state[16], u32 out[8]); | ||||||
|  | + * void hchacha_block_arm(const u32 state[16], u32 out[8], int nrounds); | ||||||
|  |   */ | ||||||
|  | -ENTRY(hchacha20_arm) | ||||||
|  | +ENTRY(hchacha_block_arm) | ||||||
|  |  	push		{r1,r4-r11,lr} | ||||||
|  |   | ||||||
|  | +	cmp		r2, #12			// ChaCha12 ? | ||||||
|  | + | ||||||
|  |  	mov		r14, r0 | ||||||
|  |  	ldmia		r14!, {r0-r11}		// load x0-x11 | ||||||
|  |  	push		{r10-r11}		// store x10-x11 to stack | ||||||
|  |  	ldm		r14, {r10-r12,r14}	// load x12-x15 | ||||||
|  |  	sub		sp, #8 | ||||||
|  |   | ||||||
|  | +	beq		1f | ||||||
|  |  	_chacha_permute	20 | ||||||
|  |   | ||||||
|  |  	// Skip over (unused0-unused1, x10-x11) | ||||||
|  | -	add		sp, #16 | ||||||
|  | +0:	add		sp, #16 | ||||||
|  |   | ||||||
|  |  	// Fix up rotations of x12-x15 | ||||||
|  |  	ror		X12, X12, #drot | ||||||
|  | @@ -458,4 +454,7 @@ ENTRY(hchacha20_arm) | ||||||
|  |  	stm		r4, {X0,X1,X2,X3,X12,X13,X14,X15} | ||||||
|  |   | ||||||
|  |  	pop		{r4-r11,pc} | ||||||
|  | -ENDPROC(hchacha20_arm) | ||||||
|  | + | ||||||
|  | +1:	_chacha_permute	12 | ||||||
|  | +	b		0b | ||||||
|  | +ENDPROC(hchacha_block_arm) | ||||||
|  | --- a/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | +++ b/arch/arm64/crypto/chacha-neon-glue.c | ||||||
|  | @@ -1,5 +1,5 @@ | ||||||
|  |  /* | ||||||
|  | - * ARM NEON accelerated ChaCha and XChaCha stream ciphers, | ||||||
|  | + * ARM NEON and scalar accelerated ChaCha and XChaCha stream ciphers, | ||||||
|  |   * including ChaCha20 (RFC7539) | ||||||
|  |   * | ||||||
|  |   * Copyright (C) 2016 - 2017 Linaro, Ltd. <ard.biesheuvel@linaro.org> | ||||||
| @@ -0,0 +1,108 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:15 +0100 | ||||||
|  | Subject: [PATCH] crypto: arm/chacha - expose ARM ChaCha routine as library | ||||||
|  |  function | ||||||
|  |  | ||||||
|  | commit a44a3430d71bad4ee56788a59fff099b291ea54c upstream. | ||||||
|  |  | ||||||
|  | Expose the accelerated NEON ChaCha routine directly as a symbol | ||||||
|  | export so that users of the ChaCha library API can use it directly. | ||||||
|  |  | ||||||
|  | Given that calls into the library API will always go through the | ||||||
|  | routines in this module if it is enabled, switch to static keys | ||||||
|  | to select the optimal implementation available (which may be none | ||||||
|  | at all, in which case we defer to the generic implementation for | ||||||
|  | all invocations). | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/arm/crypto/Kconfig       |  1 + | ||||||
|  |  arch/arm/crypto/chacha-glue.c | 41 ++++++++++++++++++++++++++++++++++- | ||||||
|  |  2 files changed, 41 insertions(+), 1 deletion(-) | ||||||
|  |  | ||||||
|  | --- a/arch/arm/crypto/Kconfig | ||||||
|  | +++ b/arch/arm/crypto/Kconfig | ||||||
|  | @@ -129,6 +129,7 @@ config CRYPTO_CRC32_ARM_CE | ||||||
|  |  config CRYPTO_CHACHA20_NEON | ||||||
|  |  	tristate "NEON and scalar accelerated ChaCha stream cipher algorithms" | ||||||
|  |  	select CRYPTO_BLKCIPHER | ||||||
|  | +	select CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  |   | ||||||
|  |  config CRYPTO_NHPOLY1305_NEON | ||||||
|  |  	tristate "NEON accelerated NHPoly1305 hash function (for Adiantum)" | ||||||
|  | --- a/arch/arm/crypto/chacha-glue.c | ||||||
|  | +++ b/arch/arm/crypto/chacha-glue.c | ||||||
|  | @@ -11,6 +11,7 @@ | ||||||
|  |  #include <crypto/internal/chacha.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  | +#include <linux/jump_label.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  |  #include <linux/module.h> | ||||||
|  |   | ||||||
|  | @@ -29,9 +30,11 @@ asmlinkage void hchacha_block_neon(const | ||||||
|  |  asmlinkage void chacha_doarm(u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  |  			     const u32 *state, int nrounds); | ||||||
|  |   | ||||||
|  | +static __ro_after_init DEFINE_STATIC_KEY_FALSE(use_neon); | ||||||
|  | + | ||||||
|  |  static inline bool neon_usable(void) | ||||||
|  |  { | ||||||
|  | -	return crypto_simd_usable(); | ||||||
|  | +	return static_branch_likely(&use_neon) && crypto_simd_usable(); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | @@ -60,6 +63,40 @@ static void chacha_doneon(u32 *state, u8 | ||||||
|  |  	} | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | +void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon_usable()) { | ||||||
|  | +		hchacha_block_arm(state, stream, nrounds); | ||||||
|  | +	} else { | ||||||
|  | +		kernel_neon_begin(); | ||||||
|  | +		hchacha_block_neon(state, stream, nrounds); | ||||||
|  | +		kernel_neon_end(); | ||||||
|  | +	} | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(hchacha_block_arch); | ||||||
|  | + | ||||||
|  | +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	chacha_init_generic(state, key, iv); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_init_arch); | ||||||
|  | + | ||||||
|  | +void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes, | ||||||
|  | +		       int nrounds) | ||||||
|  | +{ | ||||||
|  | +	if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon_usable() || | ||||||
|  | +	    bytes <= CHACHA_BLOCK_SIZE) { | ||||||
|  | +		chacha_doarm(dst, src, bytes, state, nrounds); | ||||||
|  | +		state[12] += DIV_ROUND_UP(bytes, CHACHA_BLOCK_SIZE); | ||||||
|  | +		return; | ||||||
|  | +	} | ||||||
|  | + | ||||||
|  | +	kernel_neon_begin(); | ||||||
|  | +	chacha_doneon(state, dst, src, bytes, nrounds); | ||||||
|  | +	kernel_neon_end(); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_crypt_arch); | ||||||
|  | + | ||||||
|  |  static int chacha_stream_xor(struct skcipher_request *req, | ||||||
|  |  			     const struct chacha_ctx *ctx, const u8 *iv, | ||||||
|  |  			     bool neon) | ||||||
|  | @@ -269,6 +306,8 @@ static int __init chacha_simd_mod_init(v | ||||||
|  |  			for (i = 0; i < ARRAY_SIZE(neon_algs); i++) | ||||||
|  |  				neon_algs[i].base.cra_priority = 0; | ||||||
|  |  			break; | ||||||
|  | +		default: | ||||||
|  | +			static_branch_enable(&use_neon); | ||||||
|  |  		} | ||||||
|  |   | ||||||
|  |  		err = crypto_register_skciphers(neon_algs, ARRAY_SIZE(neon_algs)); | ||||||
| @@ -0,0 +1,451 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: "Jason A. Donenfeld" <Jason@zx2c4.com> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:16 +0100 | ||||||
|  | Subject: [PATCH] crypto: mips/chacha - import 32r2 ChaCha code from Zinc | ||||||
|  | MIME-Version: 1.0 | ||||||
|  | Content-Type: text/plain; charset=UTF-8 | ||||||
|  | Content-Transfer-Encoding: 8bit | ||||||
|  |  | ||||||
|  | commit 49aa7c00eddf8d8f462b0256bd82e81762d7b0c6 upstream. | ||||||
|  |  | ||||||
|  | This imports the accelerated MIPS 32r2 ChaCha20 implementation from the | ||||||
|  | Zinc patch set. | ||||||
|  |  | ||||||
|  | Co-developed-by: René van Dorst <opensource@vdorst.com> | ||||||
|  | Signed-off-by: René van Dorst <opensource@vdorst.com> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/mips/crypto/chacha-core.S | 424 +++++++++++++++++++++++++++++++++ | ||||||
|  |  1 file changed, 424 insertions(+) | ||||||
|  |  create mode 100644 arch/mips/crypto/chacha-core.S | ||||||
|  |  | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/arch/mips/crypto/chacha-core.S | ||||||
|  | @@ -0,0 +1,424 @@ | ||||||
|  | +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ | ||||||
|  | +/* | ||||||
|  | + * Copyright (C) 2016-2018 René van Dorst <opensource@vdorst.com>. All Rights Reserved. | ||||||
|  | + * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#define MASK_U32		0x3c | ||||||
|  | +#define CHACHA20_BLOCK_SIZE	64 | ||||||
|  | +#define STACK_SIZE		32 | ||||||
|  | + | ||||||
|  | +#define X0	$t0 | ||||||
|  | +#define X1	$t1 | ||||||
|  | +#define X2	$t2 | ||||||
|  | +#define X3	$t3 | ||||||
|  | +#define X4	$t4 | ||||||
|  | +#define X5	$t5 | ||||||
|  | +#define X6	$t6 | ||||||
|  | +#define X7	$t7 | ||||||
|  | +#define X8	$t8 | ||||||
|  | +#define X9	$t9 | ||||||
|  | +#define X10	$v1 | ||||||
|  | +#define X11	$s6 | ||||||
|  | +#define X12	$s5 | ||||||
|  | +#define X13	$s4 | ||||||
|  | +#define X14	$s3 | ||||||
|  | +#define X15	$s2 | ||||||
|  | +/* Use regs which are overwritten on exit for Tx so we don't leak clear data. */ | ||||||
|  | +#define T0	$s1 | ||||||
|  | +#define T1	$s0 | ||||||
|  | +#define T(n)	T ## n | ||||||
|  | +#define X(n)	X ## n | ||||||
|  | + | ||||||
|  | +/* Input arguments */ | ||||||
|  | +#define STATE		$a0 | ||||||
|  | +#define OUT		$a1 | ||||||
|  | +#define IN		$a2 | ||||||
|  | +#define BYTES		$a3 | ||||||
|  | + | ||||||
|  | +/* Output argument */ | ||||||
|  | +/* NONCE[0] is kept in a register and not in memory. | ||||||
|  | + * We don't want to touch original value in memory. | ||||||
|  | + * Must be incremented every loop iteration. | ||||||
|  | + */ | ||||||
|  | +#define NONCE_0		$v0 | ||||||
|  | + | ||||||
|  | +/* SAVED_X and SAVED_CA are set in the jump table. | ||||||
|  | + * Use regs which are overwritten on exit else we don't leak clear data. | ||||||
|  | + * They are used to handling the last bytes which are not multiple of 4. | ||||||
|  | + */ | ||||||
|  | +#define SAVED_X		X15 | ||||||
|  | +#define SAVED_CA	$s7 | ||||||
|  | + | ||||||
|  | +#define IS_UNALIGNED	$s7 | ||||||
|  | + | ||||||
|  | +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||||||
|  | +#define MSB 0 | ||||||
|  | +#define LSB 3 | ||||||
|  | +#define ROTx rotl | ||||||
|  | +#define ROTR(n) rotr n, 24 | ||||||
|  | +#define	CPU_TO_LE32(n) \ | ||||||
|  | +	wsbh	n; \ | ||||||
|  | +	rotr	n, 16; | ||||||
|  | +#else | ||||||
|  | +#define MSB 3 | ||||||
|  | +#define LSB 0 | ||||||
|  | +#define ROTx rotr | ||||||
|  | +#define CPU_TO_LE32(n) | ||||||
|  | +#define ROTR(n) | ||||||
|  | +#endif | ||||||
|  | + | ||||||
|  | +#define FOR_EACH_WORD(x) \ | ||||||
|  | +	x( 0); \ | ||||||
|  | +	x( 1); \ | ||||||
|  | +	x( 2); \ | ||||||
|  | +	x( 3); \ | ||||||
|  | +	x( 4); \ | ||||||
|  | +	x( 5); \ | ||||||
|  | +	x( 6); \ | ||||||
|  | +	x( 7); \ | ||||||
|  | +	x( 8); \ | ||||||
|  | +	x( 9); \ | ||||||
|  | +	x(10); \ | ||||||
|  | +	x(11); \ | ||||||
|  | +	x(12); \ | ||||||
|  | +	x(13); \ | ||||||
|  | +	x(14); \ | ||||||
|  | +	x(15); | ||||||
|  | + | ||||||
|  | +#define FOR_EACH_WORD_REV(x) \ | ||||||
|  | +	x(15); \ | ||||||
|  | +	x(14); \ | ||||||
|  | +	x(13); \ | ||||||
|  | +	x(12); \ | ||||||
|  | +	x(11); \ | ||||||
|  | +	x(10); \ | ||||||
|  | +	x( 9); \ | ||||||
|  | +	x( 8); \ | ||||||
|  | +	x( 7); \ | ||||||
|  | +	x( 6); \ | ||||||
|  | +	x( 5); \ | ||||||
|  | +	x( 4); \ | ||||||
|  | +	x( 3); \ | ||||||
|  | +	x( 2); \ | ||||||
|  | +	x( 1); \ | ||||||
|  | +	x( 0); | ||||||
|  | + | ||||||
|  | +#define PLUS_ONE_0	 1 | ||||||
|  | +#define PLUS_ONE_1	 2 | ||||||
|  | +#define PLUS_ONE_2	 3 | ||||||
|  | +#define PLUS_ONE_3	 4 | ||||||
|  | +#define PLUS_ONE_4	 5 | ||||||
|  | +#define PLUS_ONE_5	 6 | ||||||
|  | +#define PLUS_ONE_6	 7 | ||||||
|  | +#define PLUS_ONE_7	 8 | ||||||
|  | +#define PLUS_ONE_8	 9 | ||||||
|  | +#define PLUS_ONE_9	10 | ||||||
|  | +#define PLUS_ONE_10	11 | ||||||
|  | +#define PLUS_ONE_11	12 | ||||||
|  | +#define PLUS_ONE_12	13 | ||||||
|  | +#define PLUS_ONE_13	14 | ||||||
|  | +#define PLUS_ONE_14	15 | ||||||
|  | +#define PLUS_ONE_15	16 | ||||||
|  | +#define PLUS_ONE(x)	PLUS_ONE_ ## x | ||||||
|  | +#define _CONCAT3(a,b,c)	a ## b ## c | ||||||
|  | +#define CONCAT3(a,b,c)	_CONCAT3(a,b,c) | ||||||
|  | + | ||||||
|  | +#define STORE_UNALIGNED(x) \ | ||||||
|  | +CONCAT3(.Lchacha20_mips_xor_unaligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  | +	.if (x != 12); \ | ||||||
|  | +		lw	T0, (x*4)(STATE); \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	lwl	T1, (x*4)+MSB ## (IN); \ | ||||||
|  | +	lwr	T1, (x*4)+LSB ## (IN); \ | ||||||
|  | +	.if (x == 12); \ | ||||||
|  | +		addu	X ## x, NONCE_0; \ | ||||||
|  | +	.else; \ | ||||||
|  | +		addu	X ## x, T0; \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	CPU_TO_LE32(X ## x); \ | ||||||
|  | +	xor	X ## x, T1; \ | ||||||
|  | +	swl	X ## x, (x*4)+MSB ## (OUT); \ | ||||||
|  | +	swr	X ## x, (x*4)+LSB ## (OUT); | ||||||
|  | + | ||||||
|  | +#define STORE_ALIGNED(x) \ | ||||||
|  | +CONCAT3(.Lchacha20_mips_xor_aligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  | +	.if (x != 12); \ | ||||||
|  | +		lw	T0, (x*4)(STATE); \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	lw	T1, (x*4) ## (IN); \ | ||||||
|  | +	.if (x == 12); \ | ||||||
|  | +		addu	X ## x, NONCE_0; \ | ||||||
|  | +	.else; \ | ||||||
|  | +		addu	X ## x, T0; \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	CPU_TO_LE32(X ## x); \ | ||||||
|  | +	xor	X ## x, T1; \ | ||||||
|  | +	sw	X ## x, (x*4) ## (OUT); | ||||||
|  | + | ||||||
|  | +/* Jump table macro. | ||||||
|  | + * Used for setup and handling the last bytes, which are not multiple of 4. | ||||||
|  | + * X15 is free to store Xn | ||||||
|  | + * Every jumptable entry must be equal in size. | ||||||
|  | + */ | ||||||
|  | +#define JMPTBL_ALIGNED(x) \ | ||||||
|  | +.Lchacha20_mips_jmptbl_aligned_ ## x: ; \ | ||||||
|  | +	.set	noreorder; \ | ||||||
|  | +	b	.Lchacha20_mips_xor_aligned_ ## x ## _b; \ | ||||||
|  | +	.if (x == 12); \ | ||||||
|  | +		addu	SAVED_X, X ## x, NONCE_0; \ | ||||||
|  | +	.else; \ | ||||||
|  | +		addu	SAVED_X, X ## x, SAVED_CA; \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	.set	reorder | ||||||
|  | + | ||||||
|  | +#define JMPTBL_UNALIGNED(x) \ | ||||||
|  | +.Lchacha20_mips_jmptbl_unaligned_ ## x: ; \ | ||||||
|  | +	.set	noreorder; \ | ||||||
|  | +	b	.Lchacha20_mips_xor_unaligned_ ## x ## _b; \ | ||||||
|  | +	.if (x == 12); \ | ||||||
|  | +		addu	SAVED_X, X ## x, NONCE_0; \ | ||||||
|  | +	.else; \ | ||||||
|  | +		addu	SAVED_X, X ## x, SAVED_CA; \ | ||||||
|  | +	.endif; \ | ||||||
|  | +	.set	reorder | ||||||
|  | + | ||||||
|  | +#define AXR(A, B, C, D,  K, L, M, N,  V, W, Y, Z,  S) \ | ||||||
|  | +	addu	X(A), X(K); \ | ||||||
|  | +	addu	X(B), X(L); \ | ||||||
|  | +	addu	X(C), X(M); \ | ||||||
|  | +	addu	X(D), X(N); \ | ||||||
|  | +	xor	X(V), X(A); \ | ||||||
|  | +	xor	X(W), X(B); \ | ||||||
|  | +	xor	X(Y), X(C); \ | ||||||
|  | +	xor	X(Z), X(D); \ | ||||||
|  | +	rotl	X(V), S;    \ | ||||||
|  | +	rotl	X(W), S;    \ | ||||||
|  | +	rotl	X(Y), S;    \ | ||||||
|  | +	rotl	X(Z), S; | ||||||
|  | + | ||||||
|  | +.text | ||||||
|  | +.set	reorder | ||||||
|  | +.set	noat | ||||||
|  | +.globl	chacha20_mips | ||||||
|  | +.ent	chacha20_mips | ||||||
|  | +chacha20_mips: | ||||||
|  | +	.frame	$sp, STACK_SIZE, $ra | ||||||
|  | + | ||||||
|  | +	addiu	$sp, -STACK_SIZE | ||||||
|  | + | ||||||
|  | +	/* Return bytes = 0. */ | ||||||
|  | +	beqz	BYTES, .Lchacha20_mips_end | ||||||
|  | + | ||||||
|  | +	lw	NONCE_0, 48(STATE) | ||||||
|  | + | ||||||
|  | +	/* Save s0-s7 */ | ||||||
|  | +	sw	$s0,  0($sp) | ||||||
|  | +	sw	$s1,  4($sp) | ||||||
|  | +	sw	$s2,  8($sp) | ||||||
|  | +	sw	$s3, 12($sp) | ||||||
|  | +	sw	$s4, 16($sp) | ||||||
|  | +	sw	$s5, 20($sp) | ||||||
|  | +	sw	$s6, 24($sp) | ||||||
|  | +	sw	$s7, 28($sp) | ||||||
|  | + | ||||||
|  | +	/* Test IN or OUT is unaligned. | ||||||
|  | +	 * IS_UNALIGNED = ( IN | OUT ) & 0x00000003 | ||||||
|  | +	 */ | ||||||
|  | +	or	IS_UNALIGNED, IN, OUT | ||||||
|  | +	andi	IS_UNALIGNED, 0x3 | ||||||
|  | + | ||||||
|  | +	/* Set number of rounds */ | ||||||
|  | +	li	$at, 20 | ||||||
|  | + | ||||||
|  | +	b	.Lchacha20_rounds_start | ||||||
|  | + | ||||||
|  | +.align 4 | ||||||
|  | +.Loop_chacha20_rounds: | ||||||
|  | +	addiu	IN,  CHACHA20_BLOCK_SIZE | ||||||
|  | +	addiu	OUT, CHACHA20_BLOCK_SIZE | ||||||
|  | +	addiu	NONCE_0, 1 | ||||||
|  | + | ||||||
|  | +.Lchacha20_rounds_start: | ||||||
|  | +	lw	X0,  0(STATE) | ||||||
|  | +	lw	X1,  4(STATE) | ||||||
|  | +	lw	X2,  8(STATE) | ||||||
|  | +	lw	X3,  12(STATE) | ||||||
|  | + | ||||||
|  | +	lw	X4,  16(STATE) | ||||||
|  | +	lw	X5,  20(STATE) | ||||||
|  | +	lw	X6,  24(STATE) | ||||||
|  | +	lw	X7,  28(STATE) | ||||||
|  | +	lw	X8,  32(STATE) | ||||||
|  | +	lw	X9,  36(STATE) | ||||||
|  | +	lw	X10, 40(STATE) | ||||||
|  | +	lw	X11, 44(STATE) | ||||||
|  | + | ||||||
|  | +	move	X12, NONCE_0 | ||||||
|  | +	lw	X13, 52(STATE) | ||||||
|  | +	lw	X14, 56(STATE) | ||||||
|  | +	lw	X15, 60(STATE) | ||||||
|  | + | ||||||
|  | +.Loop_chacha20_xor_rounds: | ||||||
|  | +	addiu	$at, -2 | ||||||
|  | +	AXR( 0, 1, 2, 3,  4, 5, 6, 7, 12,13,14,15, 16); | ||||||
|  | +	AXR( 8, 9,10,11, 12,13,14,15,  4, 5, 6, 7, 12); | ||||||
|  | +	AXR( 0, 1, 2, 3,  4, 5, 6, 7, 12,13,14,15,  8); | ||||||
|  | +	AXR( 8, 9,10,11, 12,13,14,15,  4, 5, 6, 7,  7); | ||||||
|  | +	AXR( 0, 1, 2, 3,  5, 6, 7, 4, 15,12,13,14, 16); | ||||||
|  | +	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4, 12); | ||||||
|  | +	AXR( 0, 1, 2, 3,  5, 6, 7, 4, 15,12,13,14,  8); | ||||||
|  | +	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4,  7); | ||||||
|  | +	bnez	$at, .Loop_chacha20_xor_rounds | ||||||
|  | + | ||||||
|  | +	addiu	BYTES, -(CHACHA20_BLOCK_SIZE) | ||||||
|  | + | ||||||
|  | +	/* Is data src/dst unaligned? Jump */ | ||||||
|  | +	bnez	IS_UNALIGNED, .Loop_chacha20_unaligned | ||||||
|  | + | ||||||
|  | +	/* Set number rounds here to fill delayslot. */ | ||||||
|  | +	li	$at, 20 | ||||||
|  | + | ||||||
|  | +	/* BYTES < 0, it has no full block. */ | ||||||
|  | +	bltz	BYTES, .Lchacha20_mips_no_full_block_aligned | ||||||
|  | + | ||||||
|  | +	FOR_EACH_WORD_REV(STORE_ALIGNED) | ||||||
|  | + | ||||||
|  | +	/* BYTES > 0? Loop again. */ | ||||||
|  | +	bgtz	BYTES, .Loop_chacha20_rounds | ||||||
|  | + | ||||||
|  | +	/* Place this here to fill delay slot */ | ||||||
|  | +	addiu	NONCE_0, 1 | ||||||
|  | + | ||||||
|  | +	/* BYTES < 0? Handle last bytes */ | ||||||
|  | +	bltz	BYTES, .Lchacha20_mips_xor_bytes | ||||||
|  | + | ||||||
|  | +.Lchacha20_mips_xor_done: | ||||||
|  | +	/* Restore used registers */ | ||||||
|  | +	lw	$s0,  0($sp) | ||||||
|  | +	lw	$s1,  4($sp) | ||||||
|  | +	lw	$s2,  8($sp) | ||||||
|  | +	lw	$s3, 12($sp) | ||||||
|  | +	lw	$s4, 16($sp) | ||||||
|  | +	lw	$s5, 20($sp) | ||||||
|  | +	lw	$s6, 24($sp) | ||||||
|  | +	lw	$s7, 28($sp) | ||||||
|  | + | ||||||
|  | +	/* Write NONCE_0 back to right location in state */ | ||||||
|  | +	sw	NONCE_0, 48(STATE) | ||||||
|  | + | ||||||
|  | +.Lchacha20_mips_end: | ||||||
|  | +	addiu	$sp, STACK_SIZE | ||||||
|  | +	jr	$ra | ||||||
|  | + | ||||||
|  | +.Lchacha20_mips_no_full_block_aligned: | ||||||
|  | +	/* Restore the offset on BYTES */ | ||||||
|  | +	addiu	BYTES, CHACHA20_BLOCK_SIZE | ||||||
|  | + | ||||||
|  | +	/* Get number of full WORDS */ | ||||||
|  | +	andi	$at, BYTES, MASK_U32 | ||||||
|  | + | ||||||
|  | +	/* Load upper half of jump table addr */ | ||||||
|  | +	lui	T0, %hi(.Lchacha20_mips_jmptbl_aligned_0) | ||||||
|  | + | ||||||
|  | +	/* Calculate lower half jump table offset */ | ||||||
|  | +	ins	T0, $at, 1, 6 | ||||||
|  | + | ||||||
|  | +	/* Add offset to STATE */ | ||||||
|  | +	addu	T1, STATE, $at | ||||||
|  | + | ||||||
|  | +	/* Add lower half jump table addr */ | ||||||
|  | +	addiu	T0, %lo(.Lchacha20_mips_jmptbl_aligned_0) | ||||||
|  | + | ||||||
|  | +	/* Read value from STATE */ | ||||||
|  | +	lw	SAVED_CA, 0(T1) | ||||||
|  | + | ||||||
|  | +	/* Store remaining bytecounter as negative value */ | ||||||
|  | +	subu	BYTES, $at, BYTES | ||||||
|  | + | ||||||
|  | +	jr	T0 | ||||||
|  | + | ||||||
|  | +	/* Jump table */ | ||||||
|  | +	FOR_EACH_WORD(JMPTBL_ALIGNED) | ||||||
|  | + | ||||||
|  | + | ||||||
|  | +.Loop_chacha20_unaligned: | ||||||
|  | +	/* Set number rounds here to fill delayslot. */ | ||||||
|  | +	li	$at, 20 | ||||||
|  | + | ||||||
|  | +	/* BYTES > 0, it has no full block. */ | ||||||
|  | +	bltz	BYTES, .Lchacha20_mips_no_full_block_unaligned | ||||||
|  | + | ||||||
|  | +	FOR_EACH_WORD_REV(STORE_UNALIGNED) | ||||||
|  | + | ||||||
|  | +	/* BYTES > 0? Loop again. */ | ||||||
|  | +	bgtz	BYTES, .Loop_chacha20_rounds | ||||||
|  | + | ||||||
|  | +	/* Write NONCE_0 back to right location in state */ | ||||||
|  | +	sw	NONCE_0, 48(STATE) | ||||||
|  | + | ||||||
|  | +	.set noreorder | ||||||
|  | +	/* Fall through to byte handling */ | ||||||
|  | +	bgez	BYTES, .Lchacha20_mips_xor_done | ||||||
|  | +.Lchacha20_mips_xor_unaligned_0_b: | ||||||
|  | +.Lchacha20_mips_xor_aligned_0_b: | ||||||
|  | +	/* Place this here to fill delay slot */ | ||||||
|  | +	addiu	NONCE_0, 1 | ||||||
|  | +	.set reorder | ||||||
|  | + | ||||||
|  | +.Lchacha20_mips_xor_bytes: | ||||||
|  | +	addu	IN, $at | ||||||
|  | +	addu	OUT, $at | ||||||
|  | +	/* First byte */ | ||||||
|  | +	lbu	T1, 0(IN) | ||||||
|  | +	addiu	$at, BYTES, 1 | ||||||
|  | +	CPU_TO_LE32(SAVED_X) | ||||||
|  | +	ROTR(SAVED_X) | ||||||
|  | +	xor	T1, SAVED_X | ||||||
|  | +	sb	T1, 0(OUT) | ||||||
|  | +	beqz	$at, .Lchacha20_mips_xor_done | ||||||
|  | +	/* Second byte */ | ||||||
|  | +	lbu	T1, 1(IN) | ||||||
|  | +	addiu	$at, BYTES, 2 | ||||||
|  | +	ROTx	SAVED_X, 8 | ||||||
|  | +	xor	T1, SAVED_X | ||||||
|  | +	sb	T1, 1(OUT) | ||||||
|  | +	beqz	$at, .Lchacha20_mips_xor_done | ||||||
|  | +	/* Third byte */ | ||||||
|  | +	lbu	T1, 2(IN) | ||||||
|  | +	ROTx	SAVED_X, 8 | ||||||
|  | +	xor	T1, SAVED_X | ||||||
|  | +	sb	T1, 2(OUT) | ||||||
|  | +	b	.Lchacha20_mips_xor_done | ||||||
|  | + | ||||||
|  | +.Lchacha20_mips_no_full_block_unaligned: | ||||||
|  | +	/* Restore the offset on BYTES */ | ||||||
|  | +	addiu	BYTES, CHACHA20_BLOCK_SIZE | ||||||
|  | + | ||||||
|  | +	/* Get number of full WORDS */ | ||||||
|  | +	andi	$at, BYTES, MASK_U32 | ||||||
|  | + | ||||||
|  | +	/* Load upper half of jump table addr */ | ||||||
|  | +	lui	T0, %hi(.Lchacha20_mips_jmptbl_unaligned_0) | ||||||
|  | + | ||||||
|  | +	/* Calculate lower half jump table offset */ | ||||||
|  | +	ins	T0, $at, 1, 6 | ||||||
|  | + | ||||||
|  | +	/* Add offset to STATE */ | ||||||
|  | +	addu	T1, STATE, $at | ||||||
|  | + | ||||||
|  | +	/* Add lower half jump table addr */ | ||||||
|  | +	addiu	T0, %lo(.Lchacha20_mips_jmptbl_unaligned_0) | ||||||
|  | + | ||||||
|  | +	/* Read value from STATE */ | ||||||
|  | +	lw	SAVED_CA, 0(T1) | ||||||
|  | + | ||||||
|  | +	/* Store remaining bytecounter as negative value */ | ||||||
|  | +	subu	BYTES, $at, BYTES | ||||||
|  | + | ||||||
|  | +	jr	T0 | ||||||
|  | + | ||||||
|  | +	/* Jump table */ | ||||||
|  | +	FOR_EACH_WORD(JMPTBL_UNALIGNED) | ||||||
|  | +.end chacha20_mips | ||||||
|  | +.set at | ||||||
| @@ -0,0 +1,559 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:17 +0100 | ||||||
|  | Subject: [PATCH] crypto: mips/chacha - wire up accelerated 32r2 code from Zinc | ||||||
|  | MIME-Version: 1.0 | ||||||
|  | Content-Type: text/plain; charset=UTF-8 | ||||||
|  | Content-Transfer-Encoding: 8bit | ||||||
|  |  | ||||||
|  | commit 3a2f58f3ba4f6f44e33d1a48240d5eadb882cb59 upstream. | ||||||
|  |  | ||||||
|  | This integrates the accelerated MIPS 32r2 implementation of ChaCha | ||||||
|  | into both the API and library interfaces of the kernel crypto stack. | ||||||
|  |  | ||||||
|  | The significance of this is that, in addition to becoming available | ||||||
|  | as an accelerated library implementation, it can also be used by | ||||||
|  | existing crypto API code such as Adiantum (for block encryption on | ||||||
|  | ultra low performance cores) or IPsec using chacha20poly1305. These | ||||||
|  | are use cases that have already opted into using the abstract crypto | ||||||
|  | API. In order to support Adiantum, the core assembler routine has | ||||||
|  | been adapted to take the round count as a function argument rather | ||||||
|  | than hardcoding it to 20. | ||||||
|  |  | ||||||
|  | Co-developed-by: René van Dorst <opensource@vdorst.com> | ||||||
|  | Signed-off-by: René van Dorst <opensource@vdorst.com> | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/mips/Makefile             |   2 +- | ||||||
|  |  arch/mips/crypto/Makefile      |   4 + | ||||||
|  |  arch/mips/crypto/chacha-core.S | 159 ++++++++++++++++++++++++--------- | ||||||
|  |  arch/mips/crypto/chacha-glue.c | 150 +++++++++++++++++++++++++++++++ | ||||||
|  |  crypto/Kconfig                 |   6 ++ | ||||||
|  |  5 files changed, 277 insertions(+), 44 deletions(-) | ||||||
|  |  create mode 100644 arch/mips/crypto/chacha-glue.c | ||||||
|  |  | ||||||
|  | --- a/arch/mips/Makefile | ||||||
|  | +++ b/arch/mips/Makefile | ||||||
|  | @@ -334,7 +334,7 @@ libs-$(CONFIG_MIPS_FP_SUPPORT) += arch/m | ||||||
|  |  # See arch/mips/Kbuild for content of core part of the kernel | ||||||
|  |  core-y += arch/mips/ | ||||||
|  |   | ||||||
|  | -drivers-$(CONFIG_MIPS_CRC_SUPPORT) += arch/mips/crypto/ | ||||||
|  | +drivers-y			+= arch/mips/crypto/ | ||||||
|  |  drivers-$(CONFIG_OPROFILE)	+= arch/mips/oprofile/ | ||||||
|  |   | ||||||
|  |  # suspend and hibernation support | ||||||
|  | --- a/arch/mips/crypto/Makefile | ||||||
|  | +++ b/arch/mips/crypto/Makefile | ||||||
|  | @@ -4,3 +4,7 @@ | ||||||
|  |  # | ||||||
|  |   | ||||||
|  |  obj-$(CONFIG_CRYPTO_CRC32_MIPS) += crc32-mips.o | ||||||
|  | + | ||||||
|  | +obj-$(CONFIG_CRYPTO_CHACHA_MIPS) += chacha-mips.o | ||||||
|  | +chacha-mips-y := chacha-core.o chacha-glue.o | ||||||
|  | +AFLAGS_chacha-core.o += -O2 # needed to fill branch delay slots | ||||||
|  | --- a/arch/mips/crypto/chacha-core.S | ||||||
|  | +++ b/arch/mips/crypto/chacha-core.S | ||||||
|  | @@ -125,7 +125,7 @@ | ||||||
|  |  #define CONCAT3(a,b,c)	_CONCAT3(a,b,c) | ||||||
|  |   | ||||||
|  |  #define STORE_UNALIGNED(x) \ | ||||||
|  | -CONCAT3(.Lchacha20_mips_xor_unaligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  | +CONCAT3(.Lchacha_mips_xor_unaligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  |  	.if (x != 12); \ | ||||||
|  |  		lw	T0, (x*4)(STATE); \ | ||||||
|  |  	.endif; \ | ||||||
|  | @@ -142,7 +142,7 @@ CONCAT3(.Lchacha20_mips_xor_unaligned_, | ||||||
|  |  	swr	X ## x, (x*4)+LSB ## (OUT); | ||||||
|  |   | ||||||
|  |  #define STORE_ALIGNED(x) \ | ||||||
|  | -CONCAT3(.Lchacha20_mips_xor_aligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  | +CONCAT3(.Lchacha_mips_xor_aligned_, PLUS_ONE(x), _b: ;) \ | ||||||
|  |  	.if (x != 12); \ | ||||||
|  |  		lw	T0, (x*4)(STATE); \ | ||||||
|  |  	.endif; \ | ||||||
|  | @@ -162,9 +162,9 @@ CONCAT3(.Lchacha20_mips_xor_aligned_, PL | ||||||
|  |   * Every jumptable entry must be equal in size. | ||||||
|  |   */ | ||||||
|  |  #define JMPTBL_ALIGNED(x) \ | ||||||
|  | -.Lchacha20_mips_jmptbl_aligned_ ## x: ; \ | ||||||
|  | +.Lchacha_mips_jmptbl_aligned_ ## x: ; \ | ||||||
|  |  	.set	noreorder; \ | ||||||
|  | -	b	.Lchacha20_mips_xor_aligned_ ## x ## _b; \ | ||||||
|  | +	b	.Lchacha_mips_xor_aligned_ ## x ## _b; \ | ||||||
|  |  	.if (x == 12); \ | ||||||
|  |  		addu	SAVED_X, X ## x, NONCE_0; \ | ||||||
|  |  	.else; \ | ||||||
|  | @@ -173,9 +173,9 @@ CONCAT3(.Lchacha20_mips_xor_aligned_, PL | ||||||
|  |  	.set	reorder | ||||||
|  |   | ||||||
|  |  #define JMPTBL_UNALIGNED(x) \ | ||||||
|  | -.Lchacha20_mips_jmptbl_unaligned_ ## x: ; \ | ||||||
|  | +.Lchacha_mips_jmptbl_unaligned_ ## x: ; \ | ||||||
|  |  	.set	noreorder; \ | ||||||
|  | -	b	.Lchacha20_mips_xor_unaligned_ ## x ## _b; \ | ||||||
|  | +	b	.Lchacha_mips_xor_unaligned_ ## x ## _b; \ | ||||||
|  |  	.if (x == 12); \ | ||||||
|  |  		addu	SAVED_X, X ## x, NONCE_0; \ | ||||||
|  |  	.else; \ | ||||||
|  | @@ -200,15 +200,18 @@ CONCAT3(.Lchacha20_mips_xor_aligned_, PL | ||||||
|  |  .text | ||||||
|  |  .set	reorder | ||||||
|  |  .set	noat | ||||||
|  | -.globl	chacha20_mips | ||||||
|  | -.ent	chacha20_mips | ||||||
|  | -chacha20_mips: | ||||||
|  | +.globl	chacha_crypt_arch | ||||||
|  | +.ent	chacha_crypt_arch | ||||||
|  | +chacha_crypt_arch: | ||||||
|  |  	.frame	$sp, STACK_SIZE, $ra | ||||||
|  |   | ||||||
|  | +	/* Load number of rounds */ | ||||||
|  | +	lw	$at, 16($sp) | ||||||
|  | + | ||||||
|  |  	addiu	$sp, -STACK_SIZE | ||||||
|  |   | ||||||
|  |  	/* Return bytes = 0. */ | ||||||
|  | -	beqz	BYTES, .Lchacha20_mips_end | ||||||
|  | +	beqz	BYTES, .Lchacha_mips_end | ||||||
|  |   | ||||||
|  |  	lw	NONCE_0, 48(STATE) | ||||||
|  |   | ||||||
|  | @@ -228,18 +231,15 @@ chacha20_mips: | ||||||
|  |  	or	IS_UNALIGNED, IN, OUT | ||||||
|  |  	andi	IS_UNALIGNED, 0x3 | ||||||
|  |   | ||||||
|  | -	/* Set number of rounds */ | ||||||
|  | -	li	$at, 20 | ||||||
|  | - | ||||||
|  | -	b	.Lchacha20_rounds_start | ||||||
|  | +	b	.Lchacha_rounds_start | ||||||
|  |   | ||||||
|  |  .align 4 | ||||||
|  | -.Loop_chacha20_rounds: | ||||||
|  | +.Loop_chacha_rounds: | ||||||
|  |  	addiu	IN,  CHACHA20_BLOCK_SIZE | ||||||
|  |  	addiu	OUT, CHACHA20_BLOCK_SIZE | ||||||
|  |  	addiu	NONCE_0, 1 | ||||||
|  |   | ||||||
|  | -.Lchacha20_rounds_start: | ||||||
|  | +.Lchacha_rounds_start: | ||||||
|  |  	lw	X0,  0(STATE) | ||||||
|  |  	lw	X1,  4(STATE) | ||||||
|  |  	lw	X2,  8(STATE) | ||||||
|  | @@ -259,7 +259,7 @@ chacha20_mips: | ||||||
|  |  	lw	X14, 56(STATE) | ||||||
|  |  	lw	X15, 60(STATE) | ||||||
|  |   | ||||||
|  | -.Loop_chacha20_xor_rounds: | ||||||
|  | +.Loop_chacha_xor_rounds: | ||||||
|  |  	addiu	$at, -2 | ||||||
|  |  	AXR( 0, 1, 2, 3,  4, 5, 6, 7, 12,13,14,15, 16); | ||||||
|  |  	AXR( 8, 9,10,11, 12,13,14,15,  4, 5, 6, 7, 12); | ||||||
|  | @@ -269,31 +269,31 @@ chacha20_mips: | ||||||
|  |  	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4, 12); | ||||||
|  |  	AXR( 0, 1, 2, 3,  5, 6, 7, 4, 15,12,13,14,  8); | ||||||
|  |  	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4,  7); | ||||||
|  | -	bnez	$at, .Loop_chacha20_xor_rounds | ||||||
|  | +	bnez	$at, .Loop_chacha_xor_rounds | ||||||
|  |   | ||||||
|  |  	addiu	BYTES, -(CHACHA20_BLOCK_SIZE) | ||||||
|  |   | ||||||
|  |  	/* Is data src/dst unaligned? Jump */ | ||||||
|  | -	bnez	IS_UNALIGNED, .Loop_chacha20_unaligned | ||||||
|  | +	bnez	IS_UNALIGNED, .Loop_chacha_unaligned | ||||||
|  |   | ||||||
|  |  	/* Set number rounds here to fill delayslot. */ | ||||||
|  | -	li	$at, 20 | ||||||
|  | +	lw	$at, (STACK_SIZE+16)($sp) | ||||||
|  |   | ||||||
|  |  	/* BYTES < 0, it has no full block. */ | ||||||
|  | -	bltz	BYTES, .Lchacha20_mips_no_full_block_aligned | ||||||
|  | +	bltz	BYTES, .Lchacha_mips_no_full_block_aligned | ||||||
|  |   | ||||||
|  |  	FOR_EACH_WORD_REV(STORE_ALIGNED) | ||||||
|  |   | ||||||
|  |  	/* BYTES > 0? Loop again. */ | ||||||
|  | -	bgtz	BYTES, .Loop_chacha20_rounds | ||||||
|  | +	bgtz	BYTES, .Loop_chacha_rounds | ||||||
|  |   | ||||||
|  |  	/* Place this here to fill delay slot */ | ||||||
|  |  	addiu	NONCE_0, 1 | ||||||
|  |   | ||||||
|  |  	/* BYTES < 0? Handle last bytes */ | ||||||
|  | -	bltz	BYTES, .Lchacha20_mips_xor_bytes | ||||||
|  | +	bltz	BYTES, .Lchacha_mips_xor_bytes | ||||||
|  |   | ||||||
|  | -.Lchacha20_mips_xor_done: | ||||||
|  | +.Lchacha_mips_xor_done: | ||||||
|  |  	/* Restore used registers */ | ||||||
|  |  	lw	$s0,  0($sp) | ||||||
|  |  	lw	$s1,  4($sp) | ||||||
|  | @@ -307,11 +307,11 @@ chacha20_mips: | ||||||
|  |  	/* Write NONCE_0 back to right location in state */ | ||||||
|  |  	sw	NONCE_0, 48(STATE) | ||||||
|  |   | ||||||
|  | -.Lchacha20_mips_end: | ||||||
|  | +.Lchacha_mips_end: | ||||||
|  |  	addiu	$sp, STACK_SIZE | ||||||
|  |  	jr	$ra | ||||||
|  |   | ||||||
|  | -.Lchacha20_mips_no_full_block_aligned: | ||||||
|  | +.Lchacha_mips_no_full_block_aligned: | ||||||
|  |  	/* Restore the offset on BYTES */ | ||||||
|  |  	addiu	BYTES, CHACHA20_BLOCK_SIZE | ||||||
|  |   | ||||||
|  | @@ -319,7 +319,7 @@ chacha20_mips: | ||||||
|  |  	andi	$at, BYTES, MASK_U32 | ||||||
|  |   | ||||||
|  |  	/* Load upper half of jump table addr */ | ||||||
|  | -	lui	T0, %hi(.Lchacha20_mips_jmptbl_aligned_0) | ||||||
|  | +	lui	T0, %hi(.Lchacha_mips_jmptbl_aligned_0) | ||||||
|  |   | ||||||
|  |  	/* Calculate lower half jump table offset */ | ||||||
|  |  	ins	T0, $at, 1, 6 | ||||||
|  | @@ -328,7 +328,7 @@ chacha20_mips: | ||||||
|  |  	addu	T1, STATE, $at | ||||||
|  |   | ||||||
|  |  	/* Add lower half jump table addr */ | ||||||
|  | -	addiu	T0, %lo(.Lchacha20_mips_jmptbl_aligned_0) | ||||||
|  | +	addiu	T0, %lo(.Lchacha_mips_jmptbl_aligned_0) | ||||||
|  |   | ||||||
|  |  	/* Read value from STATE */ | ||||||
|  |  	lw	SAVED_CA, 0(T1) | ||||||
|  | @@ -342,31 +342,31 @@ chacha20_mips: | ||||||
|  |  	FOR_EACH_WORD(JMPTBL_ALIGNED) | ||||||
|  |   | ||||||
|  |   | ||||||
|  | -.Loop_chacha20_unaligned: | ||||||
|  | +.Loop_chacha_unaligned: | ||||||
|  |  	/* Set number rounds here to fill delayslot. */ | ||||||
|  | -	li	$at, 20 | ||||||
|  | +	lw	$at, (STACK_SIZE+16)($sp) | ||||||
|  |   | ||||||
|  |  	/* BYTES > 0, it has no full block. */ | ||||||
|  | -	bltz	BYTES, .Lchacha20_mips_no_full_block_unaligned | ||||||
|  | +	bltz	BYTES, .Lchacha_mips_no_full_block_unaligned | ||||||
|  |   | ||||||
|  |  	FOR_EACH_WORD_REV(STORE_UNALIGNED) | ||||||
|  |   | ||||||
|  |  	/* BYTES > 0? Loop again. */ | ||||||
|  | -	bgtz	BYTES, .Loop_chacha20_rounds | ||||||
|  | +	bgtz	BYTES, .Loop_chacha_rounds | ||||||
|  |   | ||||||
|  |  	/* Write NONCE_0 back to right location in state */ | ||||||
|  |  	sw	NONCE_0, 48(STATE) | ||||||
|  |   | ||||||
|  |  	.set noreorder | ||||||
|  |  	/* Fall through to byte handling */ | ||||||
|  | -	bgez	BYTES, .Lchacha20_mips_xor_done | ||||||
|  | -.Lchacha20_mips_xor_unaligned_0_b: | ||||||
|  | -.Lchacha20_mips_xor_aligned_0_b: | ||||||
|  | +	bgez	BYTES, .Lchacha_mips_xor_done | ||||||
|  | +.Lchacha_mips_xor_unaligned_0_b: | ||||||
|  | +.Lchacha_mips_xor_aligned_0_b: | ||||||
|  |  	/* Place this here to fill delay slot */ | ||||||
|  |  	addiu	NONCE_0, 1 | ||||||
|  |  	.set reorder | ||||||
|  |   | ||||||
|  | -.Lchacha20_mips_xor_bytes: | ||||||
|  | +.Lchacha_mips_xor_bytes: | ||||||
|  |  	addu	IN, $at | ||||||
|  |  	addu	OUT, $at | ||||||
|  |  	/* First byte */ | ||||||
|  | @@ -376,22 +376,22 @@ chacha20_mips: | ||||||
|  |  	ROTR(SAVED_X) | ||||||
|  |  	xor	T1, SAVED_X | ||||||
|  |  	sb	T1, 0(OUT) | ||||||
|  | -	beqz	$at, .Lchacha20_mips_xor_done | ||||||
|  | +	beqz	$at, .Lchacha_mips_xor_done | ||||||
|  |  	/* Second byte */ | ||||||
|  |  	lbu	T1, 1(IN) | ||||||
|  |  	addiu	$at, BYTES, 2 | ||||||
|  |  	ROTx	SAVED_X, 8 | ||||||
|  |  	xor	T1, SAVED_X | ||||||
|  |  	sb	T1, 1(OUT) | ||||||
|  | -	beqz	$at, .Lchacha20_mips_xor_done | ||||||
|  | +	beqz	$at, .Lchacha_mips_xor_done | ||||||
|  |  	/* Third byte */ | ||||||
|  |  	lbu	T1, 2(IN) | ||||||
|  |  	ROTx	SAVED_X, 8 | ||||||
|  |  	xor	T1, SAVED_X | ||||||
|  |  	sb	T1, 2(OUT) | ||||||
|  | -	b	.Lchacha20_mips_xor_done | ||||||
|  | +	b	.Lchacha_mips_xor_done | ||||||
|  |   | ||||||
|  | -.Lchacha20_mips_no_full_block_unaligned: | ||||||
|  | +.Lchacha_mips_no_full_block_unaligned: | ||||||
|  |  	/* Restore the offset on BYTES */ | ||||||
|  |  	addiu	BYTES, CHACHA20_BLOCK_SIZE | ||||||
|  |   | ||||||
|  | @@ -399,7 +399,7 @@ chacha20_mips: | ||||||
|  |  	andi	$at, BYTES, MASK_U32 | ||||||
|  |   | ||||||
|  |  	/* Load upper half of jump table addr */ | ||||||
|  | -	lui	T0, %hi(.Lchacha20_mips_jmptbl_unaligned_0) | ||||||
|  | +	lui	T0, %hi(.Lchacha_mips_jmptbl_unaligned_0) | ||||||
|  |   | ||||||
|  |  	/* Calculate lower half jump table offset */ | ||||||
|  |  	ins	T0, $at, 1, 6 | ||||||
|  | @@ -408,7 +408,7 @@ chacha20_mips: | ||||||
|  |  	addu	T1, STATE, $at | ||||||
|  |   | ||||||
|  |  	/* Add lower half jump table addr */ | ||||||
|  | -	addiu	T0, %lo(.Lchacha20_mips_jmptbl_unaligned_0) | ||||||
|  | +	addiu	T0, %lo(.Lchacha_mips_jmptbl_unaligned_0) | ||||||
|  |   | ||||||
|  |  	/* Read value from STATE */ | ||||||
|  |  	lw	SAVED_CA, 0(T1) | ||||||
|  | @@ -420,5 +420,78 @@ chacha20_mips: | ||||||
|  |   | ||||||
|  |  	/* Jump table */ | ||||||
|  |  	FOR_EACH_WORD(JMPTBL_UNALIGNED) | ||||||
|  | -.end chacha20_mips | ||||||
|  | +.end chacha_crypt_arch | ||||||
|  | +.set at | ||||||
|  | + | ||||||
|  | +/* Input arguments | ||||||
|  | + * STATE	$a0 | ||||||
|  | + * OUT		$a1 | ||||||
|  | + * NROUND	$a2 | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#undef X12 | ||||||
|  | +#undef X13 | ||||||
|  | +#undef X14 | ||||||
|  | +#undef X15 | ||||||
|  | + | ||||||
|  | +#define X12	$a3 | ||||||
|  | +#define X13	$at | ||||||
|  | +#define X14	$v0 | ||||||
|  | +#define X15	STATE | ||||||
|  | + | ||||||
|  | +.set noat | ||||||
|  | +.globl	hchacha_block_arch | ||||||
|  | +.ent	hchacha_block_arch | ||||||
|  | +hchacha_block_arch: | ||||||
|  | +	.frame	$sp, STACK_SIZE, $ra | ||||||
|  | + | ||||||
|  | +	addiu	$sp, -STACK_SIZE | ||||||
|  | + | ||||||
|  | +	/* Save X11(s6) */ | ||||||
|  | +	sw	X11, 0($sp) | ||||||
|  | + | ||||||
|  | +	lw	X0,  0(STATE) | ||||||
|  | +	lw	X1,  4(STATE) | ||||||
|  | +	lw	X2,  8(STATE) | ||||||
|  | +	lw	X3,  12(STATE) | ||||||
|  | +	lw	X4,  16(STATE) | ||||||
|  | +	lw	X5,  20(STATE) | ||||||
|  | +	lw	X6,  24(STATE) | ||||||
|  | +	lw	X7,  28(STATE) | ||||||
|  | +	lw	X8,  32(STATE) | ||||||
|  | +	lw	X9,  36(STATE) | ||||||
|  | +	lw	X10, 40(STATE) | ||||||
|  | +	lw	X11, 44(STATE) | ||||||
|  | +	lw	X12, 48(STATE) | ||||||
|  | +	lw	X13, 52(STATE) | ||||||
|  | +	lw	X14, 56(STATE) | ||||||
|  | +	lw	X15, 60(STATE) | ||||||
|  | + | ||||||
|  | +.Loop_hchacha_xor_rounds: | ||||||
|  | +	addiu	$a2, -2 | ||||||
|  | +	AXR( 0, 1, 2, 3,  4, 5, 6, 7, 12,13,14,15, 16); | ||||||
|  | +	AXR( 8, 9,10,11, 12,13,14,15,  4, 5, 6, 7, 12); | ||||||
|  | +	AXR( 0, 1, 2, 3,  4, 5, 6, 7, 12,13,14,15,  8); | ||||||
|  | +	AXR( 8, 9,10,11, 12,13,14,15,  4, 5, 6, 7,  7); | ||||||
|  | +	AXR( 0, 1, 2, 3,  5, 6, 7, 4, 15,12,13,14, 16); | ||||||
|  | +	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4, 12); | ||||||
|  | +	AXR( 0, 1, 2, 3,  5, 6, 7, 4, 15,12,13,14,  8); | ||||||
|  | +	AXR(10,11, 8, 9, 15,12,13,14,  5, 6, 7, 4,  7); | ||||||
|  | +	bnez	$a2, .Loop_hchacha_xor_rounds | ||||||
|  | + | ||||||
|  | +	/* Restore used register */ | ||||||
|  | +	lw	X11, 0($sp) | ||||||
|  | + | ||||||
|  | +	sw	X0,  0(OUT) | ||||||
|  | +	sw	X1,  4(OUT) | ||||||
|  | +	sw	X2,  8(OUT) | ||||||
|  | +	sw	X3,  12(OUT) | ||||||
|  | +	sw	X12, 16(OUT) | ||||||
|  | +	sw	X13, 20(OUT) | ||||||
|  | +	sw	X14, 24(OUT) | ||||||
|  | +	sw	X15, 28(OUT) | ||||||
|  | + | ||||||
|  | +	addiu	$sp, STACK_SIZE | ||||||
|  | +	jr	$ra | ||||||
|  | +.end hchacha_block_arch | ||||||
|  |  .set at | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/arch/mips/crypto/chacha-glue.c | ||||||
|  | @@ -0,0 +1,150 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0 | ||||||
|  | +/* | ||||||
|  | + * MIPS accelerated ChaCha and XChaCha stream ciphers, | ||||||
|  | + * including ChaCha20 (RFC7539) | ||||||
|  | + * | ||||||
|  | + * Copyright (C) 2019 Linaro, Ltd. <ard.biesheuvel@linaro.org> | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <asm/byteorder.h> | ||||||
|  | +#include <crypto/algapi.h> | ||||||
|  | +#include <crypto/internal/chacha.h> | ||||||
|  | +#include <crypto/internal/skcipher.h> | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | +#include <linux/module.h> | ||||||
|  | + | ||||||
|  | +asmlinkage void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, | ||||||
|  | +				  unsigned int bytes, int nrounds); | ||||||
|  | +EXPORT_SYMBOL(chacha_crypt_arch); | ||||||
|  | + | ||||||
|  | +asmlinkage void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds); | ||||||
|  | +EXPORT_SYMBOL(hchacha_block_arch); | ||||||
|  | + | ||||||
|  | +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	chacha_init_generic(state, key, iv); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL(chacha_init_arch); | ||||||
|  | + | ||||||
|  | +static int chacha_mips_stream_xor(struct skcipher_request *req, | ||||||
|  | +				  const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  | +{ | ||||||
|  | +	struct skcipher_walk walk; | ||||||
|  | +	u32 state[16]; | ||||||
|  | +	int err; | ||||||
|  | + | ||||||
|  | +	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  | + | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  | + | ||||||
|  | +	while (walk.nbytes > 0) { | ||||||
|  | +		unsigned int nbytes = walk.nbytes; | ||||||
|  | + | ||||||
|  | +		if (nbytes < walk.total) | ||||||
|  | +			nbytes = round_down(nbytes, walk.stride); | ||||||
|  | + | ||||||
|  | +		chacha_crypt(state, walk.dst.virt.addr, walk.src.virt.addr, | ||||||
|  | +			     nbytes, ctx->nrounds); | ||||||
|  | +		err = skcipher_walk_done(&walk, walk.nbytes - nbytes); | ||||||
|  | +	} | ||||||
|  | + | ||||||
|  | +	return err; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int chacha_mips(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | +	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | + | ||||||
|  | +	return chacha_mips_stream_xor(req, ctx, req->iv); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static int xchacha_mips(struct skcipher_request *req) | ||||||
|  | +{ | ||||||
|  | +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  | +	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | +	struct chacha_ctx subctx; | ||||||
|  | +	u32 state[16]; | ||||||
|  | +	u8 real_iv[16]; | ||||||
|  | + | ||||||
|  | +	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  | + | ||||||
|  | +	hchacha_block(state, subctx.key, ctx->nrounds); | ||||||
|  | +	subctx.nrounds = ctx->nrounds; | ||||||
|  | + | ||||||
|  | +	memcpy(&real_iv[0], req->iv + 24, 8); | ||||||
|  | +	memcpy(&real_iv[8], req->iv + 16, 8); | ||||||
|  | +	return chacha_mips_stream_xor(req, &subctx, real_iv); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static struct skcipher_alg algs[] = { | ||||||
|  | +	{ | ||||||
|  | +		.base.cra_name		= "chacha20", | ||||||
|  | +		.base.cra_driver_name	= "chacha20-mips", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= CHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= chacha_mips, | ||||||
|  | +		.decrypt		= chacha_mips, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha20", | ||||||
|  | +		.base.cra_driver_name	= "xchacha20-mips", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha20_setkey, | ||||||
|  | +		.encrypt		= xchacha_mips, | ||||||
|  | +		.decrypt		= xchacha_mips, | ||||||
|  | +	}, { | ||||||
|  | +		.base.cra_name		= "xchacha12", | ||||||
|  | +		.base.cra_driver_name	= "xchacha12-mips", | ||||||
|  | +		.base.cra_priority	= 200, | ||||||
|  | +		.base.cra_blocksize	= 1, | ||||||
|  | +		.base.cra_ctxsize	= sizeof(struct chacha_ctx), | ||||||
|  | +		.base.cra_module	= THIS_MODULE, | ||||||
|  | + | ||||||
|  | +		.min_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.max_keysize		= CHACHA_KEY_SIZE, | ||||||
|  | +		.ivsize			= XCHACHA_IV_SIZE, | ||||||
|  | +		.chunksize		= CHACHA_BLOCK_SIZE, | ||||||
|  | +		.setkey			= chacha12_setkey, | ||||||
|  | +		.encrypt		= xchacha_mips, | ||||||
|  | +		.decrypt		= xchacha_mips, | ||||||
|  | +	} | ||||||
|  | +}; | ||||||
|  | + | ||||||
|  | +static int __init chacha_simd_mod_init(void) | ||||||
|  | +{ | ||||||
|  | +	return crypto_register_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static void __exit chacha_simd_mod_fini(void) | ||||||
|  | +{ | ||||||
|  | +	crypto_unregister_skciphers(algs, ARRAY_SIZE(algs)); | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +module_init(chacha_simd_mod_init); | ||||||
|  | +module_exit(chacha_simd_mod_fini); | ||||||
|  | + | ||||||
|  | +MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (MIPS accelerated)"); | ||||||
|  | +MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); | ||||||
|  | +MODULE_LICENSE("GPL v2"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("chacha20"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("chacha20-mips"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha20"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha20-mips"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha12"); | ||||||
|  | +MODULE_ALIAS_CRYPTO("xchacha12-mips"); | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -1423,6 +1423,12 @@ config CRYPTO_CHACHA20_X86_64 | ||||||
|  |  	  SSSE3, AVX2, and AVX-512VL optimized implementations of the ChaCha20, | ||||||
|  |  	  XChaCha20, and XChaCha12 stream ciphers. | ||||||
|  |   | ||||||
|  | +config CRYPTO_CHACHA_MIPS | ||||||
|  | +	tristate "ChaCha stream cipher algorithms (MIPS 32r2 optimized)" | ||||||
|  | +	depends on CPU_MIPS32_R2 | ||||||
|  | +	select CRYPTO_BLKCIPHER | ||||||
|  | +	select CRYPTO_ARCH_HAVE_LIB_CHACHA | ||||||
|  | + | ||||||
|  |  config CRYPTO_SEED | ||||||
|  |  	tristate "SEED cipher algorithm" | ||||||
|  |  	select CRYPTO_ALGAPI | ||||||
| @@ -0,0 +1,115 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:18 +0100 | ||||||
|  | Subject: [PATCH] crypto: chacha - unexport chacha_generic routines | ||||||
|  |  | ||||||
|  | commit 22cf705360707ced15f9fe5423938f313c7df536 upstream. | ||||||
|  |  | ||||||
|  | Now that all users of generic ChaCha code have moved to the core library, | ||||||
|  | there is no longer a need for the generic ChaCha skcpiher driver to | ||||||
|  | export parts of it implementation for reuse by other drivers. So drop | ||||||
|  | the exports, and make the symbols static. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  crypto/chacha_generic.c          | 26 ++++++++------------------ | ||||||
|  |  include/crypto/internal/chacha.h | 10 ---------- | ||||||
|  |  2 files changed, 8 insertions(+), 28 deletions(-) | ||||||
|  |  | ||||||
|  | --- a/crypto/chacha_generic.c | ||||||
|  | +++ b/crypto/chacha_generic.c | ||||||
|  | @@ -21,7 +21,7 @@ static int chacha_stream_xor(struct skci | ||||||
|  |   | ||||||
|  |  	err = skcipher_walk_virt(&walk, req, false); | ||||||
|  |   | ||||||
|  | -	crypto_chacha_init(state, ctx, iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, iv); | ||||||
|  |   | ||||||
|  |  	while (walk.nbytes > 0) { | ||||||
|  |  		unsigned int nbytes = walk.nbytes; | ||||||
|  | @@ -37,36 +37,27 @@ static int chacha_stream_xor(struct skci | ||||||
|  |  	return err; | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | -void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv) | ||||||
|  | -{ | ||||||
|  | -	chacha_init_generic(state, ctx->key, iv); | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_chacha_init); | ||||||
|  | - | ||||||
|  | -int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize) | ||||||
|  | +static int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +				  unsigned int keysize) | ||||||
|  |  { | ||||||
|  |  	return chacha_setkey(tfm, key, keysize, 20); | ||||||
|  |  } | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_chacha20_setkey); | ||||||
|  |   | ||||||
|  | -int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize) | ||||||
|  | +static int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | +				 unsigned int keysize) | ||||||
|  |  { | ||||||
|  |  	return chacha_setkey(tfm, key, keysize, 12); | ||||||
|  |  } | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_chacha12_setkey); | ||||||
|  |   | ||||||
|  | -int crypto_chacha_crypt(struct skcipher_request *req) | ||||||
|  | +static int crypto_chacha_crypt(struct skcipher_request *req) | ||||||
|  |  { | ||||||
|  |  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  |  	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  |   | ||||||
|  |  	return chacha_stream_xor(req, ctx, req->iv); | ||||||
|  |  } | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_chacha_crypt); | ||||||
|  |   | ||||||
|  | -int crypto_xchacha_crypt(struct skcipher_request *req) | ||||||
|  | +static int crypto_xchacha_crypt(struct skcipher_request *req) | ||||||
|  |  { | ||||||
|  |  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||||||
|  |  	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||||||
|  | @@ -75,7 +66,7 @@ int crypto_xchacha_crypt(struct skcipher | ||||||
|  |  	u8 real_iv[16]; | ||||||
|  |   | ||||||
|  |  	/* Compute the subkey given the original key and first 128 nonce bits */ | ||||||
|  | -	crypto_chacha_init(state, ctx, req->iv); | ||||||
|  | +	chacha_init_generic(state, ctx->key, req->iv); | ||||||
|  |  	hchacha_block_generic(state, subctx.key, ctx->nrounds); | ||||||
|  |  	subctx.nrounds = ctx->nrounds; | ||||||
|  |   | ||||||
|  | @@ -86,7 +77,6 @@ int crypto_xchacha_crypt(struct skcipher | ||||||
|  |  	/* Generate the stream and XOR it with the data */ | ||||||
|  |  	return chacha_stream_xor(req, &subctx, real_iv); | ||||||
|  |  } | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_xchacha_crypt); | ||||||
|  |   | ||||||
|  |  static struct skcipher_alg algs[] = { | ||||||
|  |  	{ | ||||||
|  | --- a/include/crypto/internal/chacha.h | ||||||
|  | +++ b/include/crypto/internal/chacha.h | ||||||
|  | @@ -12,8 +12,6 @@ struct chacha_ctx { | ||||||
|  |  	int nrounds; | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  | -void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv); | ||||||
|  | - | ||||||
|  |  static inline int chacha_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  |  				unsigned int keysize, int nrounds) | ||||||
|  |  { | ||||||
|  | @@ -42,12 +40,4 @@ static int inline chacha12_setkey(struct | ||||||
|  |  	return chacha_setkey(tfm, key, keysize, 12); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  | -int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize); | ||||||
|  | -int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||||||
|  | -			   unsigned int keysize); | ||||||
|  | - | ||||||
|  | -int crypto_chacha_crypt(struct skcipher_request *req); | ||||||
|  | -int crypto_xchacha_crypt(struct skcipher_request *req); | ||||||
|  | - | ||||||
|  |  #endif /* _CRYPTO_CHACHA_H */ | ||||||
| @@ -0,0 +1,649 @@ | |||||||
|  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||||||
|  | From: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Date: Fri, 8 Nov 2019 13:22:19 +0100 | ||||||
|  | Subject: [PATCH] crypto: poly1305 - move core routines into a separate library | ||||||
|  |  | ||||||
|  | commit 48ea8c6ebc96bc0990e12ee1c43d0832c23576bb upstream. | ||||||
|  |  | ||||||
|  | Move the core Poly1305 routines shared between the generic Poly1305 | ||||||
|  | shash driver and the Adiantum and NHPoly1305 drivers into a separate | ||||||
|  | library so that using just this pieces does not pull in the crypto | ||||||
|  | API pieces of the generic Poly1305 routine. | ||||||
|  |  | ||||||
|  | In a subsequent patch, we will augment this generic library with | ||||||
|  | init/update/final routines so that Poyl1305 algorithm can be used | ||||||
|  | directly without the need for using the crypto API's shash abstraction. | ||||||
|  |  | ||||||
|  | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||||||
|  | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | ||||||
|  | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> | ||||||
|  | --- | ||||||
|  |  arch/x86/crypto/poly1305_glue.c    |   2 +- | ||||||
|  |  crypto/Kconfig                     |   5 +- | ||||||
|  |  crypto/adiantum.c                  |   5 +- | ||||||
|  |  crypto/nhpoly1305.c                |   3 +- | ||||||
|  |  crypto/poly1305_generic.c          | 195 ++--------------------------- | ||||||
|  |  include/crypto/internal/poly1305.h |  67 ++++++++++ | ||||||
|  |  include/crypto/poly1305.h          |  23 ---- | ||||||
|  |  lib/crypto/Kconfig                 |   3 + | ||||||
|  |  lib/crypto/Makefile                |   3 + | ||||||
|  |  lib/crypto/poly1305.c              | 158 +++++++++++++++++++++++ | ||||||
|  |  10 files changed, 248 insertions(+), 216 deletions(-) | ||||||
|  |  create mode 100644 include/crypto/internal/poly1305.h | ||||||
|  |  create mode 100644 lib/crypto/poly1305.c | ||||||
|  |  | ||||||
|  | --- a/arch/x86/crypto/poly1305_glue.c | ||||||
|  | +++ b/arch/x86/crypto/poly1305_glue.c | ||||||
|  | @@ -7,8 +7,8 @@ | ||||||
|  |   | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  |  #include <crypto/internal/hash.h> | ||||||
|  | +#include <crypto/internal/poly1305.h> | ||||||
|  |  #include <crypto/internal/simd.h> | ||||||
|  | -#include <crypto/poly1305.h> | ||||||
|  |  #include <linux/crypto.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  |  #include <linux/module.h> | ||||||
|  | --- a/crypto/Kconfig | ||||||
|  | +++ b/crypto/Kconfig | ||||||
|  | @@ -446,7 +446,7 @@ config CRYPTO_KEYWRAP | ||||||
|  |  config CRYPTO_NHPOLY1305 | ||||||
|  |  	tristate | ||||||
|  |  	select CRYPTO_HASH | ||||||
|  | -	select CRYPTO_POLY1305 | ||||||
|  | +	select CRYPTO_LIB_POLY1305_GENERIC | ||||||
|  |   | ||||||
|  |  config CRYPTO_NHPOLY1305_SSE2 | ||||||
|  |  	tristate "NHPoly1305 hash function (x86_64 SSE2 implementation)" | ||||||
|  | @@ -467,7 +467,7 @@ config CRYPTO_NHPOLY1305_AVX2 | ||||||
|  |  config CRYPTO_ADIANTUM | ||||||
|  |  	tristate "Adiantum support" | ||||||
|  |  	select CRYPTO_CHACHA20 | ||||||
|  | -	select CRYPTO_POLY1305 | ||||||
|  | +	select CRYPTO_LIB_POLY1305_GENERIC | ||||||
|  |  	select CRYPTO_NHPOLY1305 | ||||||
|  |  	select CRYPTO_MANAGER | ||||||
|  |  	help | ||||||
|  | @@ -686,6 +686,7 @@ config CRYPTO_GHASH | ||||||
|  |  config CRYPTO_POLY1305 | ||||||
|  |  	tristate "Poly1305 authenticator algorithm" | ||||||
|  |  	select CRYPTO_HASH | ||||||
|  | +	select CRYPTO_LIB_POLY1305_GENERIC | ||||||
|  |  	help | ||||||
|  |  	  Poly1305 authenticator algorithm, RFC7539. | ||||||
|  |   | ||||||
|  | --- a/crypto/adiantum.c | ||||||
|  | +++ b/crypto/adiantum.c | ||||||
|  | @@ -33,6 +33,7 @@ | ||||||
|  |  #include <crypto/b128ops.h> | ||||||
|  |  #include <crypto/chacha.h> | ||||||
|  |  #include <crypto/internal/hash.h> | ||||||
|  | +#include <crypto/internal/poly1305.h> | ||||||
|  |  #include <crypto/internal/skcipher.h> | ||||||
|  |  #include <crypto/nhpoly1305.h> | ||||||
|  |  #include <crypto/scatterwalk.h> | ||||||
|  | @@ -242,11 +243,11 @@ static void adiantum_hash_header(struct | ||||||
|  |   | ||||||
|  |  	BUILD_BUG_ON(sizeof(header) % POLY1305_BLOCK_SIZE != 0); | ||||||
|  |  	poly1305_core_blocks(&state, &tctx->header_hash_key, | ||||||
|  | -			     &header, sizeof(header) / POLY1305_BLOCK_SIZE); | ||||||
|  | +			     &header, sizeof(header) / POLY1305_BLOCK_SIZE, 1); | ||||||
|  |   | ||||||
|  |  	BUILD_BUG_ON(TWEAK_SIZE % POLY1305_BLOCK_SIZE != 0); | ||||||
|  |  	poly1305_core_blocks(&state, &tctx->header_hash_key, req->iv, | ||||||
|  | -			     TWEAK_SIZE / POLY1305_BLOCK_SIZE); | ||||||
|  | +			     TWEAK_SIZE / POLY1305_BLOCK_SIZE, 1); | ||||||
|  |   | ||||||
|  |  	poly1305_core_emit(&state, &rctx->header_hash); | ||||||
|  |  } | ||||||
|  | --- a/crypto/nhpoly1305.c | ||||||
|  | +++ b/crypto/nhpoly1305.c | ||||||
|  | @@ -33,6 +33,7 @@ | ||||||
|  |  #include <asm/unaligned.h> | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  |  #include <crypto/internal/hash.h> | ||||||
|  | +#include <crypto/internal/poly1305.h> | ||||||
|  |  #include <crypto/nhpoly1305.h> | ||||||
|  |  #include <linux/crypto.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  | @@ -78,7 +79,7 @@ static void process_nh_hash_value(struct | ||||||
|  |  	BUILD_BUG_ON(NH_HASH_BYTES % POLY1305_BLOCK_SIZE != 0); | ||||||
|  |   | ||||||
|  |  	poly1305_core_blocks(&state->poly_state, &key->poly_key, state->nh_hash, | ||||||
|  | -			     NH_HASH_BYTES / POLY1305_BLOCK_SIZE); | ||||||
|  | +			     NH_HASH_BYTES / POLY1305_BLOCK_SIZE, 1); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  /* | ||||||
|  | --- a/crypto/poly1305_generic.c | ||||||
|  | +++ b/crypto/poly1305_generic.c | ||||||
|  | @@ -13,27 +13,12 @@ | ||||||
|  |   | ||||||
|  |  #include <crypto/algapi.h> | ||||||
|  |  #include <crypto/internal/hash.h> | ||||||
|  | -#include <crypto/poly1305.h> | ||||||
|  | +#include <crypto/internal/poly1305.h> | ||||||
|  |  #include <linux/crypto.h> | ||||||
|  |  #include <linux/kernel.h> | ||||||
|  |  #include <linux/module.h> | ||||||
|  |  #include <asm/unaligned.h> | ||||||
|  |   | ||||||
|  | -static inline u64 mlt(u64 a, u64 b) | ||||||
|  | -{ | ||||||
|  | -	return a * b; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static inline u32 sr(u64 v, u_char n) | ||||||
|  | -{ | ||||||
|  | -	return v >> n; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -static inline u32 and(u32 v, u32 mask) | ||||||
|  | -{ | ||||||
|  | -	return v & mask; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  |  int crypto_poly1305_init(struct shash_desc *desc) | ||||||
|  |  { | ||||||
|  |  	struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc); | ||||||
|  | @@ -47,124 +32,8 @@ int crypto_poly1305_init(struct shash_de | ||||||
|  |  } | ||||||
|  |  EXPORT_SYMBOL_GPL(crypto_poly1305_init); | ||||||
|  |   | ||||||
|  | -void poly1305_core_setkey(struct poly1305_key *key, const u8 *raw_key) | ||||||
|  | -{ | ||||||
|  | -	/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ | ||||||
|  | -	key->r[0] = (get_unaligned_le32(raw_key +  0) >> 0) & 0x3ffffff; | ||||||
|  | -	key->r[1] = (get_unaligned_le32(raw_key +  3) >> 2) & 0x3ffff03; | ||||||
|  | -	key->r[2] = (get_unaligned_le32(raw_key +  6) >> 4) & 0x3ffc0ff; | ||||||
|  | -	key->r[3] = (get_unaligned_le32(raw_key +  9) >> 6) & 0x3f03fff; | ||||||
|  | -	key->r[4] = (get_unaligned_le32(raw_key + 12) >> 8) & 0x00fffff; | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL_GPL(poly1305_core_setkey); | ||||||
|  | - | ||||||
|  | -/* | ||||||
|  | - * Poly1305 requires a unique key for each tag, which implies that we can't set | ||||||
|  | - * it on the tfm that gets accessed by multiple users simultaneously. Instead we | ||||||
|  | - * expect the key as the first 32 bytes in the update() call. | ||||||
|  | - */ | ||||||
|  | -unsigned int crypto_poly1305_setdesckey(struct poly1305_desc_ctx *dctx, | ||||||
|  | -					const u8 *src, unsigned int srclen) | ||||||
|  | -{ | ||||||
|  | -	if (!dctx->sset) { | ||||||
|  | -		if (!dctx->rset && srclen >= POLY1305_BLOCK_SIZE) { | ||||||
|  | -			poly1305_core_setkey(&dctx->r, src); | ||||||
|  | -			src += POLY1305_BLOCK_SIZE; | ||||||
|  | -			srclen -= POLY1305_BLOCK_SIZE; | ||||||
|  | -			dctx->rset = true; | ||||||
|  | -		} | ||||||
|  | -		if (srclen >= POLY1305_BLOCK_SIZE) { | ||||||
|  | -			dctx->s[0] = get_unaligned_le32(src +  0); | ||||||
|  | -			dctx->s[1] = get_unaligned_le32(src +  4); | ||||||
|  | -			dctx->s[2] = get_unaligned_le32(src +  8); | ||||||
|  | -			dctx->s[3] = get_unaligned_le32(src + 12); | ||||||
|  | -			src += POLY1305_BLOCK_SIZE; | ||||||
|  | -			srclen -= POLY1305_BLOCK_SIZE; | ||||||
|  | -			dctx->sset = true; | ||||||
|  | -		} | ||||||
|  | -	} | ||||||
|  | -	return srclen; | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL_GPL(crypto_poly1305_setdesckey); | ||||||
|  | - | ||||||
|  | -static void poly1305_blocks_internal(struct poly1305_state *state, | ||||||
|  | -				     const struct poly1305_key *key, | ||||||
|  | -				     const void *src, unsigned int nblocks, | ||||||
|  | -				     u32 hibit) | ||||||
|  | -{ | ||||||
|  | -	u32 r0, r1, r2, r3, r4; | ||||||
|  | -	u32 s1, s2, s3, s4; | ||||||
|  | -	u32 h0, h1, h2, h3, h4; | ||||||
|  | -	u64 d0, d1, d2, d3, d4; | ||||||
|  | - | ||||||
|  | -	if (!nblocks) | ||||||
|  | -		return; | ||||||
|  | - | ||||||
|  | -	r0 = key->r[0]; | ||||||
|  | -	r1 = key->r[1]; | ||||||
|  | -	r2 = key->r[2]; | ||||||
|  | -	r3 = key->r[3]; | ||||||
|  | -	r4 = key->r[4]; | ||||||
|  | - | ||||||
|  | -	s1 = r1 * 5; | ||||||
|  | -	s2 = r2 * 5; | ||||||
|  | -	s3 = r3 * 5; | ||||||
|  | -	s4 = r4 * 5; | ||||||
|  | - | ||||||
|  | -	h0 = state->h[0]; | ||||||
|  | -	h1 = state->h[1]; | ||||||
|  | -	h2 = state->h[2]; | ||||||
|  | -	h3 = state->h[3]; | ||||||
|  | -	h4 = state->h[4]; | ||||||
|  | - | ||||||
|  | -	do { | ||||||
|  | -		/* h += m[i] */ | ||||||
|  | -		h0 += (get_unaligned_le32(src +  0) >> 0) & 0x3ffffff; | ||||||
|  | -		h1 += (get_unaligned_le32(src +  3) >> 2) & 0x3ffffff; | ||||||
|  | -		h2 += (get_unaligned_le32(src +  6) >> 4) & 0x3ffffff; | ||||||
|  | -		h3 += (get_unaligned_le32(src +  9) >> 6) & 0x3ffffff; | ||||||
|  | -		h4 += (get_unaligned_le32(src + 12) >> 8) | hibit; | ||||||
|  | - | ||||||
|  | -		/* h *= r */ | ||||||
|  | -		d0 = mlt(h0, r0) + mlt(h1, s4) + mlt(h2, s3) + | ||||||
|  | -		     mlt(h3, s2) + mlt(h4, s1); | ||||||
|  | -		d1 = mlt(h0, r1) + mlt(h1, r0) + mlt(h2, s4) + | ||||||
|  | -		     mlt(h3, s3) + mlt(h4, s2); | ||||||
|  | -		d2 = mlt(h0, r2) + mlt(h1, r1) + mlt(h2, r0) + | ||||||
|  | -		     mlt(h3, s4) + mlt(h4, s3); | ||||||
|  | -		d3 = mlt(h0, r3) + mlt(h1, r2) + mlt(h2, r1) + | ||||||
|  | -		     mlt(h3, r0) + mlt(h4, s4); | ||||||
|  | -		d4 = mlt(h0, r4) + mlt(h1, r3) + mlt(h2, r2) + | ||||||
|  | -		     mlt(h3, r1) + mlt(h4, r0); | ||||||
|  | - | ||||||
|  | -		/* (partial) h %= p */ | ||||||
|  | -		d1 += sr(d0, 26);     h0 = and(d0, 0x3ffffff); | ||||||
|  | -		d2 += sr(d1, 26);     h1 = and(d1, 0x3ffffff); | ||||||
|  | -		d3 += sr(d2, 26);     h2 = and(d2, 0x3ffffff); | ||||||
|  | -		d4 += sr(d3, 26);     h3 = and(d3, 0x3ffffff); | ||||||
|  | -		h0 += sr(d4, 26) * 5; h4 = and(d4, 0x3ffffff); | ||||||
|  | -		h1 += h0 >> 26;       h0 = h0 & 0x3ffffff; | ||||||
|  | - | ||||||
|  | -		src += POLY1305_BLOCK_SIZE; | ||||||
|  | -	} while (--nblocks); | ||||||
|  | - | ||||||
|  | -	state->h[0] = h0; | ||||||
|  | -	state->h[1] = h1; | ||||||
|  | -	state->h[2] = h2; | ||||||
|  | -	state->h[3] = h3; | ||||||
|  | -	state->h[4] = h4; | ||||||
|  | -} | ||||||
|  | - | ||||||
|  | -void poly1305_core_blocks(struct poly1305_state *state, | ||||||
|  | -			  const struct poly1305_key *key, | ||||||
|  | -			  const void *src, unsigned int nblocks) | ||||||
|  | -{ | ||||||
|  | -	poly1305_blocks_internal(state, key, src, nblocks, 1 << 24); | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL_GPL(poly1305_core_blocks); | ||||||
|  | - | ||||||
|  | -static void poly1305_blocks(struct poly1305_desc_ctx *dctx, | ||||||
|  | -			    const u8 *src, unsigned int srclen, u32 hibit) | ||||||
|  | +static void poly1305_blocks(struct poly1305_desc_ctx *dctx, const u8 *src, | ||||||
|  | +			    unsigned int srclen) | ||||||
|  |  { | ||||||
|  |  	unsigned int datalen; | ||||||
|  |   | ||||||
|  | @@ -174,8 +43,8 @@ static void poly1305_blocks(struct poly1 | ||||||
|  |  		srclen = datalen; | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  | -	poly1305_blocks_internal(&dctx->h, &dctx->r, | ||||||
|  | -				 src, srclen / POLY1305_BLOCK_SIZE, hibit); | ||||||
|  | +	poly1305_core_blocks(&dctx->h, &dctx->r, src, | ||||||
|  | +			     srclen / POLY1305_BLOCK_SIZE, 1); | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |  int crypto_poly1305_update(struct shash_desc *desc, | ||||||
|  | @@ -193,13 +62,13 @@ int crypto_poly1305_update(struct shash_ | ||||||
|  |   | ||||||
|  |  		if (dctx->buflen == POLY1305_BLOCK_SIZE) { | ||||||
|  |  			poly1305_blocks(dctx, dctx->buf, | ||||||
|  | -					POLY1305_BLOCK_SIZE, 1 << 24); | ||||||
|  | +					POLY1305_BLOCK_SIZE); | ||||||
|  |  			dctx->buflen = 0; | ||||||
|  |  		} | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  |  	if (likely(srclen >= POLY1305_BLOCK_SIZE)) { | ||||||
|  | -		poly1305_blocks(dctx, src, srclen, 1 << 24); | ||||||
|  | +		poly1305_blocks(dctx, src, srclen); | ||||||
|  |  		src += srclen - (srclen % POLY1305_BLOCK_SIZE); | ||||||
|  |  		srclen %= POLY1305_BLOCK_SIZE; | ||||||
|  |  	} | ||||||
|  | @@ -213,54 +82,6 @@ int crypto_poly1305_update(struct shash_ | ||||||
|  |  } | ||||||
|  |  EXPORT_SYMBOL_GPL(crypto_poly1305_update); | ||||||
|  |   | ||||||
|  | -void poly1305_core_emit(const struct poly1305_state *state, void *dst) | ||||||
|  | -{ | ||||||
|  | -	u32 h0, h1, h2, h3, h4; | ||||||
|  | -	u32 g0, g1, g2, g3, g4; | ||||||
|  | -	u32 mask; | ||||||
|  | - | ||||||
|  | -	/* fully carry h */ | ||||||
|  | -	h0 = state->h[0]; | ||||||
|  | -	h1 = state->h[1]; | ||||||
|  | -	h2 = state->h[2]; | ||||||
|  | -	h3 = state->h[3]; | ||||||
|  | -	h4 = state->h[4]; | ||||||
|  | - | ||||||
|  | -	h2 += (h1 >> 26);     h1 = h1 & 0x3ffffff; | ||||||
|  | -	h3 += (h2 >> 26);     h2 = h2 & 0x3ffffff; | ||||||
|  | -	h4 += (h3 >> 26);     h3 = h3 & 0x3ffffff; | ||||||
|  | -	h0 += (h4 >> 26) * 5; h4 = h4 & 0x3ffffff; | ||||||
|  | -	h1 += (h0 >> 26);     h0 = h0 & 0x3ffffff; | ||||||
|  | - | ||||||
|  | -	/* compute h + -p */ | ||||||
|  | -	g0 = h0 + 5; | ||||||
|  | -	g1 = h1 + (g0 >> 26);             g0 &= 0x3ffffff; | ||||||
|  | -	g2 = h2 + (g1 >> 26);             g1 &= 0x3ffffff; | ||||||
|  | -	g3 = h3 + (g2 >> 26);             g2 &= 0x3ffffff; | ||||||
|  | -	g4 = h4 + (g3 >> 26) - (1 << 26); g3 &= 0x3ffffff; | ||||||
|  | - | ||||||
|  | -	/* select h if h < p, or h + -p if h >= p */ | ||||||
|  | -	mask = (g4 >> ((sizeof(u32) * 8) - 1)) - 1; | ||||||
|  | -	g0 &= mask; | ||||||
|  | -	g1 &= mask; | ||||||
|  | -	g2 &= mask; | ||||||
|  | -	g3 &= mask; | ||||||
|  | -	g4 &= mask; | ||||||
|  | -	mask = ~mask; | ||||||
|  | -	h0 = (h0 & mask) | g0; | ||||||
|  | -	h1 = (h1 & mask) | g1; | ||||||
|  | -	h2 = (h2 & mask) | g2; | ||||||
|  | -	h3 = (h3 & mask) | g3; | ||||||
|  | -	h4 = (h4 & mask) | g4; | ||||||
|  | - | ||||||
|  | -	/* h = h % (2^128) */ | ||||||
|  | -	put_unaligned_le32((h0 >>  0) | (h1 << 26), dst +  0); | ||||||
|  | -	put_unaligned_le32((h1 >>  6) | (h2 << 20), dst +  4); | ||||||
|  | -	put_unaligned_le32((h2 >> 12) | (h3 << 14), dst +  8); | ||||||
|  | -	put_unaligned_le32((h3 >> 18) | (h4 <<  8), dst + 12); | ||||||
|  | -} | ||||||
|  | -EXPORT_SYMBOL_GPL(poly1305_core_emit); | ||||||
|  | - | ||||||
|  |  int crypto_poly1305_final(struct shash_desc *desc, u8 *dst) | ||||||
|  |  { | ||||||
|  |  	struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc); | ||||||
|  | @@ -274,7 +95,7 @@ int crypto_poly1305_final(struct shash_d | ||||||
|  |  		dctx->buf[dctx->buflen++] = 1; | ||||||
|  |  		memset(dctx->buf + dctx->buflen, 0, | ||||||
|  |  		       POLY1305_BLOCK_SIZE - dctx->buflen); | ||||||
|  | -		poly1305_blocks(dctx, dctx->buf, POLY1305_BLOCK_SIZE, 0); | ||||||
|  | +		poly1305_core_blocks(&dctx->h, &dctx->r, dctx->buf, 1, 0); | ||||||
|  |  	} | ||||||
|  |   | ||||||
|  |  	poly1305_core_emit(&dctx->h, digest); | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/include/crypto/internal/poly1305.h | ||||||
|  | @@ -0,0 +1,67 @@ | ||||||
|  | +/* SPDX-License-Identifier: GPL-2.0 */ | ||||||
|  | +/* | ||||||
|  | + * Common values for the Poly1305 algorithm | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#ifndef _CRYPTO_INTERNAL_POLY1305_H | ||||||
|  | +#define _CRYPTO_INTERNAL_POLY1305_H | ||||||
|  | + | ||||||
|  | +#include <asm/unaligned.h> | ||||||
|  | +#include <linux/types.h> | ||||||
|  | +#include <crypto/poly1305.h> | ||||||
|  | + | ||||||
|  | +struct shash_desc; | ||||||
|  | + | ||||||
|  | +/* | ||||||
|  | + * Poly1305 core functions.  These implement the ε-almost-∆-universal hash | ||||||
|  | + * function underlying the Poly1305 MAC, i.e. they don't add an encrypted nonce | ||||||
|  | + * ("s key") at the end.  They also only support block-aligned inputs. | ||||||
|  | + */ | ||||||
|  | +void poly1305_core_setkey(struct poly1305_key *key, const u8 *raw_key); | ||||||
|  | +static inline void poly1305_core_init(struct poly1305_state *state) | ||||||
|  | +{ | ||||||
|  | +	*state = (struct poly1305_state){}; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +void poly1305_core_blocks(struct poly1305_state *state, | ||||||
|  | +			  const struct poly1305_key *key, const void *src, | ||||||
|  | +			  unsigned int nblocks, u32 hibit); | ||||||
|  | +void poly1305_core_emit(const struct poly1305_state *state, void *dst); | ||||||
|  | + | ||||||
|  | +/* Crypto API helper functions for the Poly1305 MAC */ | ||||||
|  | +int crypto_poly1305_init(struct shash_desc *desc); | ||||||
|  | + | ||||||
|  | +int crypto_poly1305_update(struct shash_desc *desc, | ||||||
|  | +			   const u8 *src, unsigned int srclen); | ||||||
|  | +int crypto_poly1305_final(struct shash_desc *desc, u8 *dst); | ||||||
|  | + | ||||||
|  | +/* | ||||||
|  | + * Poly1305 requires a unique key for each tag, which implies that we can't set | ||||||
|  | + * it on the tfm that gets accessed by multiple users simultaneously. Instead we | ||||||
|  | + * expect the key as the first 32 bytes in the update() call. | ||||||
|  | + */ | ||||||
|  | +static inline | ||||||
|  | +unsigned int crypto_poly1305_setdesckey(struct poly1305_desc_ctx *dctx, | ||||||
|  | +					const u8 *src, unsigned int srclen) | ||||||
|  | +{ | ||||||
|  | +	if (!dctx->sset) { | ||||||
|  | +		if (!dctx->rset && srclen >= POLY1305_BLOCK_SIZE) { | ||||||
|  | +			poly1305_core_setkey(&dctx->r, src); | ||||||
|  | +			src += POLY1305_BLOCK_SIZE; | ||||||
|  | +			srclen -= POLY1305_BLOCK_SIZE; | ||||||
|  | +			dctx->rset = true; | ||||||
|  | +		} | ||||||
|  | +		if (srclen >= POLY1305_BLOCK_SIZE) { | ||||||
|  | +			dctx->s[0] = get_unaligned_le32(src +  0); | ||||||
|  | +			dctx->s[1] = get_unaligned_le32(src +  4); | ||||||
|  | +			dctx->s[2] = get_unaligned_le32(src +  8); | ||||||
|  | +			dctx->s[3] = get_unaligned_le32(src + 12); | ||||||
|  | +			src += POLY1305_BLOCK_SIZE; | ||||||
|  | +			srclen -= POLY1305_BLOCK_SIZE; | ||||||
|  | +			dctx->sset = true; | ||||||
|  | +		} | ||||||
|  | +	} | ||||||
|  | +	return srclen; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +#endif | ||||||
|  | --- a/include/crypto/poly1305.h | ||||||
|  | +++ b/include/crypto/poly1305.h | ||||||
|  | @@ -38,27 +38,4 @@ struct poly1305_desc_ctx { | ||||||
|  |  	bool sset; | ||||||
|  |  }; | ||||||
|  |   | ||||||
|  | -/* | ||||||
|  | - * Poly1305 core functions.  These implement the ε-almost-∆-universal hash | ||||||
|  | - * function underlying the Poly1305 MAC, i.e. they don't add an encrypted nonce | ||||||
|  | - * ("s key") at the end.  They also only support block-aligned inputs. | ||||||
|  | - */ | ||||||
|  | -void poly1305_core_setkey(struct poly1305_key *key, const u8 *raw_key); | ||||||
|  | -static inline void poly1305_core_init(struct poly1305_state *state) | ||||||
|  | -{ | ||||||
|  | -	memset(state->h, 0, sizeof(state->h)); | ||||||
|  | -} | ||||||
|  | -void poly1305_core_blocks(struct poly1305_state *state, | ||||||
|  | -			  const struct poly1305_key *key, | ||||||
|  | -			  const void *src, unsigned int nblocks); | ||||||
|  | -void poly1305_core_emit(const struct poly1305_state *state, void *dst); | ||||||
|  | - | ||||||
|  | -/* Crypto API helper functions for the Poly1305 MAC */ | ||||||
|  | -int crypto_poly1305_init(struct shash_desc *desc); | ||||||
|  | -unsigned int crypto_poly1305_setdesckey(struct poly1305_desc_ctx *dctx, | ||||||
|  | -					const u8 *src, unsigned int srclen); | ||||||
|  | -int crypto_poly1305_update(struct shash_desc *desc, | ||||||
|  | -			   const u8 *src, unsigned int srclen); | ||||||
|  | -int crypto_poly1305_final(struct shash_desc *desc, u8 *dst); | ||||||
|  | - | ||||||
|  |  #endif | ||||||
|  | --- a/lib/crypto/Kconfig | ||||||
|  | +++ b/lib/crypto/Kconfig | ||||||
|  | @@ -37,5 +37,8 @@ config CRYPTO_LIB_CHACHA | ||||||
|  |  config CRYPTO_LIB_DES | ||||||
|  |  	tristate | ||||||
|  |   | ||||||
|  | +config CRYPTO_LIB_POLY1305_GENERIC | ||||||
|  | +	tristate | ||||||
|  | + | ||||||
|  |  config CRYPTO_LIB_SHA256 | ||||||
|  |  	tristate | ||||||
|  | --- a/lib/crypto/Makefile | ||||||
|  | +++ b/lib/crypto/Makefile | ||||||
|  | @@ -13,5 +13,8 @@ libarc4-y					:= arc4.o | ||||||
|  |  obj-$(CONFIG_CRYPTO_LIB_DES)			+= libdes.o | ||||||
|  |  libdes-y					:= des.o | ||||||
|  |   | ||||||
|  | +obj-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC)	+= libpoly1305.o | ||||||
|  | +libpoly1305-y					:= poly1305.o | ||||||
|  | + | ||||||
|  |  obj-$(CONFIG_CRYPTO_LIB_SHA256)			+= libsha256.o | ||||||
|  |  libsha256-y					:= sha256.o | ||||||
|  | --- /dev/null | ||||||
|  | +++ b/lib/crypto/poly1305.c | ||||||
|  | @@ -0,0 +1,158 @@ | ||||||
|  | +// SPDX-License-Identifier: GPL-2.0-or-later | ||||||
|  | +/* | ||||||
|  | + * Poly1305 authenticator algorithm, RFC7539 | ||||||
|  | + * | ||||||
|  | + * Copyright (C) 2015 Martin Willi | ||||||
|  | + * | ||||||
|  | + * Based on public domain code by Andrew Moon and Daniel J. Bernstein. | ||||||
|  | + */ | ||||||
|  | + | ||||||
|  | +#include <crypto/internal/poly1305.h> | ||||||
|  | +#include <linux/kernel.h> | ||||||
|  | +#include <linux/module.h> | ||||||
|  | +#include <asm/unaligned.h> | ||||||
|  | + | ||||||
|  | +static inline u64 mlt(u64 a, u64 b) | ||||||
|  | +{ | ||||||
|  | +	return a * b; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline u32 sr(u64 v, u_char n) | ||||||
|  | +{ | ||||||
|  | +	return v >> n; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +static inline u32 and(u32 v, u32 mask) | ||||||
|  | +{ | ||||||
|  | +	return v & mask; | ||||||
|  | +} | ||||||
|  | + | ||||||
|  | +void poly1305_core_setkey(struct poly1305_key *key, const u8 *raw_key) | ||||||
|  | +{ | ||||||
|  | +	/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ | ||||||
|  | +	key->r[0] = (get_unaligned_le32(raw_key +  0) >> 0) & 0x3ffffff; | ||||||
|  | +	key->r[1] = (get_unaligned_le32(raw_key +  3) >> 2) & 0x3ffff03; | ||||||
|  | +	key->r[2] = (get_unaligned_le32(raw_key +  6) >> 4) & 0x3ffc0ff; | ||||||
|  | +	key->r[3] = (get_unaligned_le32(raw_key +  9) >> 6) & 0x3f03fff; | ||||||
|  | +	key->r[4] = (get_unaligned_le32(raw_key + 12) >> 8) & 0x00fffff; | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL_GPL(poly1305_core_setkey); | ||||||
|  | + | ||||||
|  | +void poly1305_core_blocks(struct poly1305_state *state, | ||||||
|  | +			  const struct poly1305_key *key, const void *src, | ||||||
|  | +			  unsigned int nblocks, u32 hibit) | ||||||
|  | +{ | ||||||
|  | +	u32 r0, r1, r2, r3, r4; | ||||||
|  | +	u32 s1, s2, s3, s4; | ||||||
|  | +	u32 h0, h1, h2, h3, h4; | ||||||
|  | +	u64 d0, d1, d2, d3, d4; | ||||||
|  | + | ||||||
|  | +	if (!nblocks) | ||||||
|  | +		return; | ||||||
|  | + | ||||||
|  | +	r0 = key->r[0]; | ||||||
|  | +	r1 = key->r[1]; | ||||||
|  | +	r2 = key->r[2]; | ||||||
|  | +	r3 = key->r[3]; | ||||||
|  | +	r4 = key->r[4]; | ||||||
|  | + | ||||||
|  | +	s1 = r1 * 5; | ||||||
|  | +	s2 = r2 * 5; | ||||||
|  | +	s3 = r3 * 5; | ||||||
|  | +	s4 = r4 * 5; | ||||||
|  | + | ||||||
|  | +	h0 = state->h[0]; | ||||||
|  | +	h1 = state->h[1]; | ||||||
|  | +	h2 = state->h[2]; | ||||||
|  | +	h3 = state->h[3]; | ||||||
|  | +	h4 = state->h[4]; | ||||||
|  | + | ||||||
|  | +	do { | ||||||
|  | +		/* h += m[i] */ | ||||||
|  | +		h0 += (get_unaligned_le32(src +  0) >> 0) & 0x3ffffff; | ||||||
|  | +		h1 += (get_unaligned_le32(src +  3) >> 2) & 0x3ffffff; | ||||||
|  | +		h2 += (get_unaligned_le32(src +  6) >> 4) & 0x3ffffff; | ||||||
|  | +		h3 += (get_unaligned_le32(src +  9) >> 6) & 0x3ffffff; | ||||||
|  | +		h4 += (get_unaligned_le32(src + 12) >> 8) | (hibit << 24); | ||||||
|  | + | ||||||
|  | +		/* h *= r */ | ||||||
|  | +		d0 = mlt(h0, r0) + mlt(h1, s4) + mlt(h2, s3) + | ||||||
|  | +		     mlt(h3, s2) + mlt(h4, s1); | ||||||
|  | +		d1 = mlt(h0, r1) + mlt(h1, r0) + mlt(h2, s4) + | ||||||
|  | +		     mlt(h3, s3) + mlt(h4, s2); | ||||||
|  | +		d2 = mlt(h0, r2) + mlt(h1, r1) + mlt(h2, r0) + | ||||||
|  | +		     mlt(h3, s4) + mlt(h4, s3); | ||||||
|  | +		d3 = mlt(h0, r3) + mlt(h1, r2) + mlt(h2, r1) + | ||||||
|  | +		     mlt(h3, r0) + mlt(h4, s4); | ||||||
|  | +		d4 = mlt(h0, r4) + mlt(h1, r3) + mlt(h2, r2) + | ||||||
|  | +		     mlt(h3, r1) + mlt(h4, r0); | ||||||
|  | + | ||||||
|  | +		/* (partial) h %= p */ | ||||||
|  | +		d1 += sr(d0, 26);     h0 = and(d0, 0x3ffffff); | ||||||
|  | +		d2 += sr(d1, 26);     h1 = and(d1, 0x3ffffff); | ||||||
|  | +		d3 += sr(d2, 26);     h2 = and(d2, 0x3ffffff); | ||||||
|  | +		d4 += sr(d3, 26);     h3 = and(d3, 0x3ffffff); | ||||||
|  | +		h0 += sr(d4, 26) * 5; h4 = and(d4, 0x3ffffff); | ||||||
|  | +		h1 += h0 >> 26;       h0 = h0 & 0x3ffffff; | ||||||
|  | + | ||||||
|  | +		src += POLY1305_BLOCK_SIZE; | ||||||
|  | +	} while (--nblocks); | ||||||
|  | + | ||||||
|  | +	state->h[0] = h0; | ||||||
|  | +	state->h[1] = h1; | ||||||
|  | +	state->h[2] = h2; | ||||||
|  | +	state->h[3] = h3; | ||||||
|  | +	state->h[4] = h4; | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL_GPL(poly1305_core_blocks); | ||||||
|  | + | ||||||
|  | +void poly1305_core_emit(const struct poly1305_state *state, void *dst) | ||||||
|  | +{ | ||||||
|  | +	u32 h0, h1, h2, h3, h4; | ||||||
|  | +	u32 g0, g1, g2, g3, g4; | ||||||
|  | +	u32 mask; | ||||||
|  | + | ||||||
|  | +	/* fully carry h */ | ||||||
|  | +	h0 = state->h[0]; | ||||||
|  | +	h1 = state->h[1]; | ||||||
|  | +	h2 = state->h[2]; | ||||||
|  | +	h3 = state->h[3]; | ||||||
|  | +	h4 = state->h[4]; | ||||||
|  | + | ||||||
|  | +	h2 += (h1 >> 26);     h1 = h1 & 0x3ffffff; | ||||||
|  | +	h3 += (h2 >> 26);     h2 = h2 & 0x3ffffff; | ||||||
|  | +	h4 += (h3 >> 26);     h3 = h3 & 0x3ffffff; | ||||||
|  | +	h0 += (h4 >> 26) * 5; h4 = h4 & 0x3ffffff; | ||||||
|  | +	h1 += (h0 >> 26);     h0 = h0 & 0x3ffffff; | ||||||
|  | + | ||||||
|  | +	/* compute h + -p */ | ||||||
|  | +	g0 = h0 + 5; | ||||||
|  | +	g1 = h1 + (g0 >> 26);             g0 &= 0x3ffffff; | ||||||
|  | +	g2 = h2 + (g1 >> 26);             g1 &= 0x3ffffff; | ||||||
|  | +	g3 = h3 + (g2 >> 26);             g2 &= 0x3ffffff; | ||||||
|  | +	g4 = h4 + (g3 >> 26) - (1 << 26); g3 &= 0x3ffffff; | ||||||
|  | + | ||||||
|  | +	/* select h if h < p, or h + -p if h >= p */ | ||||||
|  | +	mask = (g4 >> ((sizeof(u32) * 8) - 1)) - 1; | ||||||
|  | +	g0 &= mask; | ||||||
|  | +	g1 &= mask; | ||||||
|  | +	g2 &= mask; | ||||||
|  | +	g3 &= mask; | ||||||
|  | +	g4 &= mask; | ||||||
|  | +	mask = ~mask; | ||||||
|  | +	h0 = (h0 & mask) | g0; | ||||||
|  | +	h1 = (h1 & mask) | g1; | ||||||
|  | +	h2 = (h2 & mask) | g2; | ||||||
|  | +	h3 = (h3 & mask) | g3; | ||||||
|  | +	h4 = (h4 & mask) | g4; | ||||||
|  | + | ||||||
|  | +	/* h = h % (2^128) */ | ||||||
|  | +	put_unaligned_le32((h0 >>  0) | (h1 << 26), dst +  0); | ||||||
|  | +	put_unaligned_le32((h1 >>  6) | (h2 << 20), dst +  4); | ||||||
|  | +	put_unaligned_le32((h2 >> 12) | (h3 << 14), dst +  8); | ||||||
|  | +	put_unaligned_le32((h3 >> 18) | (h4 <<  8), dst + 12); | ||||||
|  | +} | ||||||
|  | +EXPORT_SYMBOL_GPL(poly1305_core_emit); | ||||||
|  | + | ||||||
|  | +MODULE_LICENSE("GPL"); | ||||||
|  | +MODULE_AUTHOR("Martin Willi <martin@strongswan.org>"); | ||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user