include $(RT28xx_DIR)/os/linux/config.mk

obj_ap :=
obj_sta :=
obj_p2p :=
obj_wsc :=
obj_vht :=
obj_cmm := \
        ../../common/crypt_md5.o\
        ../../common/crypt_sha2.o\
        ../../common/crypt_hmac.o\
        ../../common/crypt_aes.o\
        ../../common/crypt_arc4.o\
        ../../common/mlme.o\
        ../../common/cmm_wep.o\
        ../../common/action.o\
        ../../common/cmm_data.o\
        ../../common/rtmp_init.o\
        ../../common/rtmp_init_inf.o\
        ../../common/cmm_tkip.o\
        ../../common/cmm_aes.o\
        ../../common/cmm_sync.o\
        ../../common/eeprom.o\
        ../../common/cmm_sanity.o\
        ../../common/cmm_info.o\
        ../../common/cmm_cfg.o\
        ../../common/cmm_wpa.o\
        ../../common/cmm_radar.o\
        ../../common/spectrum.o\
        ../../common/rtmp_timer.o\
        ../../common/rt_channel.o\
        ../../common/cmm_profile.o\
        ../../common/scan.o\
        ../../common/cmm_cmd.o\
	    ../../common/ps.o\
	    ../../common/sys_log.o\
	    ../../common/txpower.o\
        ../../rate_ctrl/ra_ctrl.o\
        ../../rate_ctrl/alg_legacy.o\
        ../../rate_ctrl/alg_ags.o\
        ../../chips/rtmp_chip.o\
        ../../mgmt/mgmt_hw.o\
        ../../mgmt/mgmt_entrytb.o\
        ../../tx_rx/wdev.o\
        ../../tx_rx/wdev_tx.o\
        ../../tx_rx/wdev_rx.o\
	    ../../os/linux/rt_profile.o


#########################################
#   ASIC related source files
#########################################
obj_mac :=
obj_phy := ../../phy/phy.o\
		../../phy/rf.o

ifeq ($(HAS_RTMP_BBP),y)
obj_phy += ../../phy/rtmp_phy.o
endif

ifeq ($(HAS_RLT_BBP),y)
obj_phy += ../../phy/rlt_phy.o
endif

ifeq ($(HAS_MT_BBP),y)
obj_phy += ../../phy/mt_phy.o
endif

ifeq ($(HAS_MT_RF),y)
obj_phy += ../../phy/mt_rf.o
endif

ifeq ($(HAS_RLT_RF),y)
obj_phy += ../../phy/rlt_rf.o
endif

ifeq ($(HAS_RT_RF),y)
obj_phy += ../../phy/rt_rf.o
endif

ifeq ($(HAS_MAC_PCI),y)
obj_mac += ../../common/cmm_mac_pci.o\
	../../common/cmm_data_pci.o\
	../../os/linux/rt_rbus_pci_drv.o\
	../../hif/hif_pci.o

ifeq ($(HAS_ATE),y)
#obj_mac += ../../ate/inf/ate_pci.o
endif

ifeq ($(OSABL),NO)
obj_mac += \
	../../os/linux/rt_pci_rbus.o\
	../../os/linux/rt_rbus_pci_util.o
endif
endif

ifeq ($(HAS_MAC_USB),y)
obj_mac += ../../common/cmm_mac_usb.o
endif

ifeq ($(HAS_MAC_SDIO),y)
obj_mac += ../../common/cmm_mac_sdio.o
endif

ifeq ($(HAS_RLT_MAC),y)
obj_mac += ../../hw_ctrl/cmm_asic.o
obj_mac += ../../mac/rtmp_mac.o
obj_mac += ../../mac/ral_nmac.o
obj_mac += ../../common/ral_ps.o
endif

ifeq ($(HAS_RTMP_MAC),y)
obj_mac += ../../hw_ctrl/cmm_asic.o
obj_mac += ../../mac/rtmp_mac.o
obj_mac += ../../mac/ral_omac.o
obj_mac += ../../common/ral_ps.o
endif

ifeq ($(HAS_MT_MAC),y)
obj_mac += ../../hw_ctrl/cmm_asic_mt.o
obj_mac += ../../hw_ctrl/cmm_chip_mt.o
obj_mac += ../../hw_ctrl/mt_gpio.o
obj_mac += ../../mac/mt_mac.o
obj_mac += ../../common/mt_ps.o
obj_mac += ../../common/mt_io.o
obj_mac += ../../tx_rx/txs.o
endif


#########################################
#   Itnterface related source files
#########################################
obj_inf :=
ifeq ($(HAS_INF_USB),y)
obj_inf += ../../common/cmm_mac_usb.o\
	../../common/rtusb_data.o\
	../../common/cmm_usb_io.o\
	../../common/cmm_data_usb.o\
	../../common/rtusb_bulk.o\
	../../os/linux/rt_usb.o

ifeq ($(HAS_RTMP_MAC),y)
obj_inf += ../../common/rtusb_io.o
endif

ifeq ($(HAS_RLT_MAC),y)
obj_inf += ../../common/rtusb_io.o
endif

ifeq ($(HAS_MT_MAC),y)
obj_inf += ../../common/mtusb_io.o
endif

ifeq ($(OSABL),NO)
obj_inf += ../../common/rtusb_dev_id.o\
        ../../os/linux/rt_usb_util.o\
        ../../os/linux/usb_main_dev.o
endif

ifeq ($(HAS_ATE),y)
obj_inf += ../../ate/inf/ate_usb.o
endif
endif

ifeq ($(HAS_INF_SDIO),y)
obj_inf += ../../os/linux/rt_sdio.o\
		../../common/mtsdio_io.o\
		../../common/mtsdio_data.o\
        ../../common/cmm_data_sdio.o\
        ../../os/linux/sdio_main_dev.o
endif
ifeq ($(HAS_MAC_USB),y)

endif

ifeq ($(HAS_INF_PCI),y)
ifeq ($(OSABL),NO)
obj_inf += ../../os/linux/pci_main_dev.o
endif
endif

ifeq ($(HAS_INF_RBUS),y)
ifeq ($(OSABL),NO)
obj_inf += ../../os/linux/rbus_main_dev.o
endif
endif

obj_cmm += $(obj_phy) $(obj_mac) $(obj_inf)

#########################################
#   System Feature related source files
#########################################

ifeq ($(HAS_UAPSD_SUPPORT),y)
obj_cmm += ../../common/uapsd.o
endif

ifeq ($(HAS_BLOCK_NET_IF),y)
obj_cmm += ../../common/netif_block.o
endif

ifeq ($(HAS_NEW_RATE_ADAPT_SUPPORT),y)
obj_cmm += ../../rate_ctrl/alg_grp.o
endif

ifeq ($(HAS_RATE_ADAPT_AGS_SUPPORT),y)
obj_cmm += ../../rate_ctrl/alg_ags.o
endif

ifeq ($(HAS_DFS_SUPPORT),y)
obj_cmm += ../../common/cmm_dfs.o
endif

ifeq ($(HAS_CS_SUPPORT),y)
obj_cmm += ../../common/cmm_cs.o
endif

#ifdef LED_CONTROL_SUPPORT
ifeq ($(HAS_LED_CONTROL_SUPPORT),y)
obj_cmm += ../../common/rt_led.o
endif
#endif // LED_CONTROL_SUPPORT //

#ifdef ANDES_FIRMWARE_SUPPORT
ifeq ($(HAS_ANDES_FIRMWARE_SUPPORT),y)
obj_cmm += ../../mcu/rtmp_and.o
endif
#endif /* ANDES_FIRMWARE_SUPPORT */

#ifdef WAPI_SUPPORT
ifeq ($(HAS_WAPI_SUPPORT),y)
obj_cmm += ../../common/wapi.o
obj_cmm += ../../common/wapi_crypt.o
obj_cmm += ../../common/wapi_sms4.o
endif
#endif // WAPI_SUPPORT //

#ifdef DOT11K_RRM_SUPPORT
ifeq ($(HAS_DOT11K_RRM_SUPPORT),y)
obj_cmm += \
	../../common/rrm_tlv.o\
	../../common/rrm_sanity.o\
	../../common/rrm.o
endif
#endif // DOT11K_RRM_SUPPORT //

#ifdef DOT11V_WNM_SUPPORT
ifeq ($(HAS_DOT11V_WNM_SUPPORT),y)
obj_cmm += \
    ../../common/wnm_tlv.o\
    ../../common/wnm.o
endif
#endif // DOT11V_WNM_SUPPORT //

#ifdef DOT11W_PMF_SUPPORT
ifeq ($(HAS_DOT11W_PMF_SUPPORT),y)
obj_cmm += ../../common/pmf.o
endif
#endif // DOT11W_PMF_SUPPORT //


#ifdef DOT11_N_SUPPORT
ifeq ($(HAS_DOT11_N_SUPPORT),y)
obj_cmm += \
        ../../common/ba_action.o\
        ../../mgmt/mgmt_ht.o

endif
#endif // DOT11_N_SUPPORT //

#ifdef DOT11_VHT_SUPPORT
ifeq ($(HAS_DOT11_VHT_SUPPORT),y)
obj_vht += ../../mgmt/mgmt_vht.o\
	../../common/vht.o
endif
#endif // DOT11_VHT_SUPPORT //


#ifdef WSC_INCLUDED
ifeq ($(HAS_WSC),y)
obj_wsc += \
        ../../common/wsc.o\
        ../../common/wsc_tlv.o\
        ../../common/crypt_biginteger.o\
        ../../common/crypt_dh.o
endif

ifeq ($(HAS_WSC_V2),y)
obj_wsc += ../../common/wsc_v2.o
endif
ifeq ($(HAS_WSC_NFC),y)
obj_wsc += ../../common/nfc.o
endif
#endif // WSC_INCLUDED //


#ifdef DOT11R_FT_SUPPORT
ifeq ($(HAS_DOT11R_FT_SUPPORT),y)
obj_cmm += \
	../../common/ft.o\
	../../common/ft_tlv.o\
	../../common/ft_iocl.o\
	../../common/ft_rc.o
endif
#endif // DOT11R_FT_SUPPORT //



#ifdef CONFIG_HOTSPOT
ifeq ($(HAS_HOTSPOT_SUPPORT),y)
obj_cmm += \
		../../common/wnm.o\
		../../common/gas.o\
		../../common/hotspot.o
endif		
#endif // CONFIG_HOTSPOT //

#ifdef ALL_NET_EVENT
ifeq ($(HAS_ALL_NET_EVENT),y)
obj_cmm += \
		../../common/all_net_event.o
endif		
#endif // ALL_NET_EVENT //

###############################################################################
#
# config for AP mode
#
###############################################################################

#ifdef CONFIG_AP_SUPPORT
ifeq ($(RT28xx_MODE),AP)
obj_ap += \
	../../ap/ap_mbss.o\
	../../ap/ap.o\
	../../ap/ap_assoc.o\
	../../ap/ap_auth.o\
	../../ap/ap_connect.o\
	../../ap/ap_mlme.o\
	../../ap/ap_sanity.o\
	../../ap/ap_sync.o\
	../../ap/ap_wpa.o\
	../../ap/ap_data.o\
	../../ap/ap_autoChSel.o\
	../../ap/ap_qload.o\
	../../ap/ap_cfg.o\
	../../ap/ap_nps.o

ifeq ($(HAS_QOS_DLS_SUPPORT),y)
obj_ap += ../../ap/ap_dls.o
endif

ifeq ($(HAS_IDS_SUPPORT),y)
obj_ap += ../../ap/ap_ids.o
endif

ifeq ($(HAS_WSC),y)
obj_ap += ../../common/wsc_ufd.o
endif

#ifdef DOT11R_FT_SUPPORT
ifeq ($(HAS_DOT11R_FT_SUPPORT),y)
obj_ap += ../../ap/ap_ftkd.o
endif
#endif // DOT11R_FT_SUPPORT //


ifeq ($(HAS_WDS),y)
obj_ap += ../../ap/ap_wds.o

ifeq ($(OSABL),NO)
obj_ap += ../../ap/ap_wds_inf.o
endif
endif

ifeq ($(OSABL),NO)
obj_ap += \
    ../../ap/ap_mbss_inf.o\
	../../os/linux/ap_ioctl.o
endif

#ifdef APCLI_SUPPORT
ifeq ($(HAS_APCLI),y)
obj_ap += \
	../../ap/ap_apcli.o \
	../../ap/apcli_ctrl.o \
	../../ap/apcli_sync.o \
	../../ap/apcli_auth.o \
	../../ap/apcli_assoc.o \
	../../common/cmm_mat.o \
	../../common/cmm_mat_iparp.o \
	../../common/cmm_mat_pppoe.o \
	../../common/cmm_mat_ipv6.o


ifeq ($(HAS_MAC_REPEATER_SUPPORT),y)
obj_ap += ../../ap/ap_repeater.o
endif

ifeq ($(OSABL),NO)
obj_ap += ../../ap/ap_apcli_inf.o
endif
endif
#endif // APCLI_SUPPORT //


ifeq ($(HAS_CLIENT_WDS_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/client_wds.o
endif

ifeq ($(HAS_IGMP_SNOOP_SUPPORT),y)
obj_ap += ../../common/igmp_snoop.o
endif

MOD_NAME = $(MODULE)_ap
DAT_PATH = /etc/Wireless/RT$(CHIPSET_DAT)AP
DAT_FILE_NAME = conf/RT$(CHIPSET_DAT)AP.dat
endif
#endif // CONFIG_AP_SUPPORT //


###############################################################################
#
# config for STA mode
#
###############################################################################



###############################################################################
#
# config for AP/STA mixed mode
#
###############################################################################



###############################################################################
#
# Module Base
#
###############################################################################

obj-m := $(MOD_NAME).o

#ifdef CONFIG_AP_SUPPORT
ifeq ($(RT28xx_MODE),AP)

$(MOD_NAME)-objs := \
	$(obj_ap)\
	$(obj_vht)\
	$(obj_cmm)\
	$(obj_wsc)\
	$(obj_phy)

ifeq ($(HAS_ATE),y)
#$(MOD_NAME)-objs += ../../ate/rt_mac/rt_ate.o
$(MOD_NAME)-objs += ../../ate/ate_agent.o
endif

ifeq ($(HAS_QA_SUPPORT),y)
#$(MOD_NAME)-objs += ../../ate/rt_mac/rt_qa.o
$(MOD_NAME)-objs += ../../ate/qa_agent.o
endif

#ifdef MULTI_INF_SUPPORT
ifeq ($(HAS_MULTI_INF),y)
$(MOD_NAME)-objs += ../../os/linux/multi_main_dev.o
endif
#endif // MULTI_INF_SUPPORT //

#ifdef BG_FT_SUPPORT
ifeq ($(OSABL),NO)
ifeq ($(HAS_BGFP_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/br_ftph.o
endif
endif
#endif // BG_FT_SUPPORT //

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../common/rt_os_util.o\
	../../os/linux/rt_linux.o\
        ../../os/linux/rt_txrx_hook.o\
	../../os/linux/rt_main_dev.o

#ifdef CONFIG_TRACE_SUPPORT
CFLAGS_rt_linux.o = -I$(RT28xx_DIR)/include/os
#endif

ifeq ($(HAS_SNIFFER_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../sniffer/sniffer_prism.o	\
	../../sniffer/sniffer_radiotap.o

ifeq ($(HAS_SNIFFER_MIB_CMD),y)
 $(MOD_NAME)-objs += \
	../../ap/sniffer_mib.o
endif

endif

ifeq ($(HAS_ACL_V2_SUPPORT),y)
 $(MOD_NAME)-objs += \
	../../ap/ap_acl_v2.o
endif


else
$(MOD_NAME)-objs += \
	../../os/linux/rt_symb.o
endif

#ifdef CRDA_SUPPORT
ifeq ($(OSABL),NO)
ifeq ($(HAS_CFG80211_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/cfg80211/cfg80211.o\
	../../os/linux/cfg80211/cfg80211_util.o\
	../../os/linux/cfg80211/cfg80211_scan.o\
	../../os/linux/cfg80211/cfg80211_rx.o\
	../../os/linux/cfg80211/cfg80211_tx.o\
	../../os/linux/cfg80211/cfg80211_inf.o\
	../../os/linux/cfg80211/cfg80211_p2p.o\
	../../os/linux/cfg80211/cfg80211_ap.o\
	../../os/linux/cfg80211/cfg80211drv.o\
        ../../os/linux/cfg80211/cfg80211_tdls.o
endif
endif

ifeq ($(OSABL),YES)
ifeq ($(HAS_CFG80211_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/cfg80211/cfg80211_scan.o\
	../../os/linux/cfg80211/cfg80211_rx.o\
        ../../os/linux/cfg80211/cfg80211_tx.o\
        ../../os/linux/cfg80211/cfg80211_inf.o\
	../../os/linux/cfg80211/cfg80211_p2p.o\
	../../os/linux/cfg80211/cfg80211_ap.o\
	../../os/linux/cfg80211/cfg80211drv.o
endif
endif
#endif // CRDA_SUPPORT //

ifeq ($(HAS_RT2880_RT2860_COEXIST),y)	
RT28XX_AP_OBJ += \
	../../os/linux/rt_pci_rbus.o\
	../../os/linux/rt_rbus_pci_util.o\
	../../os/linux/pci_main_dev.o\
	../../common/dfs.o
endif


ifeq ($(PLATFORM),IKANOS_V160)
$(MOD_NAME)-objs += ../../os/linux/vr_ikans.o
endif

ifeq ($(PLATFORM),IKANOS_V180)
$(MOD_NAME)-objs += ../../os/linux/vr_ikans.o
endif

ifeq ($(PLATFORM),BL2348)
ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += ../../os/linux/vr_bdlt.o
endif
endif
#ifdef PLATFORM_BL23570
ifeq ($(PLATFORM),BL23570)
rt$(CHIPSET)ap-objs += \
        ../../os/linux/vr_bdlt.o
endif
#endif // PLATFORM_BL23570 //

ifeq ($(HAS_EASY_CONFIG_SETUP_SUPPORT),y)
ifeq ($(PLATFORM),RALINK_3052)
$(MOD_NAME)-objs += lib.a
endif
endif

endif
#endif // CONFIG_AP_SUPPORT //




#chip releated
















#ifdef RTMP_MAC_PCI
#endif // RTMP_MAC_PCI //








#ifdef RTMP_MAC_PCI
#endif //RTMP_MAC_PCI//






#ifdef MT7603
ifneq ($(or $(findstring mt7603e,$(CHIPSET)),$(findstring mt7603u,$(CHIPSET))),)
$(MOD_NAME)-objs += \
		../../common/ee_efuse.o\
		../../common/ee_prom.o\
		../../chips/mt7603.o\
		../../mcu/mcu.o\
		../../mcu/andes_core.o\
		../../mcu/andes_mt.o

ifeq ($(HAS_ATE),y)
$(MOD_NAME)-objs += ../../ate/mt_mac/mt_ate.o
endif

endif
#endif // MT7603 //










PHONY := clean install uninstall

clean:
	rm -f ../../common/*.o
	rm -f ../../common/.*.{cmd,flags,d}
	rm -f ../../os/linux/*.{o,ko,mod.{o,c}}
	rm -f ../../os/linux/.*.{cmd,flags,d}
	rm -fr ../../os/linux/.tmp_versions
#Must clean Module.symvers; or you will suffer symbol version not match
#when OS_ABL = YES.
	rm -f ../../os/linux/Module.symvers
	rm -f ../../os/linux/Modules.symvers
	rm -f ../../os/linux/Module.markers
	rm -f ../../os/linux/modules.order
	rm -f ../../chips/*.o
	rm -f ../../chips/.*.{cmd,flags,d}
ifeq ($(RT28xx_MODE),AP)
	rm -f ../../ap/*.o
	rm -f ../../ap/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),STA)
	rm -f ../../sta/*.o
	rm -f ../../sta/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),APSTA)
	rm -f ../../ap/*.o
	rm -f ../../ap/.*.{cmd,flags,d}
	rm -f ../../sta/*.o
	rm -f ../../sta/.*.{cmd,flags,d}
endif
endif
endif

install:
	rm -rf $(DAT_PATH)
	$(shell [ ! -f /etc/Wireless ] && mkdir /etc/Wireless)
	mkdir $(DAT_PATH)
	cp $(RT28xx_DIR)/$(DAT_FILE_NAME) $(DAT_PATH)/.
	install -d $(LINUX_SRC_MODULE)
	install -m 644 -c $(addsuffix .ko,$(MOD_NAME)) $(LINUX_SRC_MODULE)
	/sbin/depmod -a ${shell uname -r}

uninstall:
#	rm -rf $(DAT_PATH)
	rm -rf $(addprefix $(LINUX_SRC_MODULE),$(addsuffix .ko,$(MOD_NAME)))
	/sbin/depmod -a ${shell uname -r}

# Declare the contents of the .PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
